
  -- oUF_D3Orbs2 layout by roth - 2009
  
  -- Version 1.5.3 (01/4/11)
  -- oUF D3Orbs - update completed April 05, 2010 - users can now move the orbs and the art, hide or show the art via menu command.  Update performed by Tagger.
  -- oUF D3Orbs - update Mar 18 2010 - eliminated need to reload UI upon color change in all scenarios
  -- oUF_D3Orbs - last update Mar 16 2010 - added user menu and ability to select any color for health, mana, and combat. Update performed by Tagger.
  -- oUF_D3Orbs - aesthetic modifications done by Tagger - last update Mar 06, 2010 (added combat tracking to the orbs,
  -- they will now have a red aura surrounding the inner galaxy glow while in combat, and will change back to the default player
  -- selection out of combat
  -- 01/04/11 - general cleanup of the LightWeight Version, removing old, unneeded code.  Adding user scaling.
  -----------------------------
  -- VARIABLES + CONFIG
  -----------------------------
  
  local myname, _ = UnitName("player")
  local _, myclass = UnitClass("player")
  local dudustance, vehiclepower, playerinvehicle
  local stringecheck = "reset"
  local update_liveAngelDemon = nil
  local update_powers = nil
  local scale_default = 0.82
  
  -- 0 = off
  -- 1 = on
  
  --size of the orbs
  local orbsize = 150

  -- shall frames be moved
  -- set this to 0 to reset all frame positions
  local allow_frame_movement = 1
  
  -- set this to 1 after you have moved everything in place
  -- THIS IS IMPORTANT because it will deactivate the mouse clickablity on that frame.
  local lock_all_frames = 1
  
  --font used
  local d3font = "FONTS\\FRIZQT__.ttf"  
  
  --player scale determination
  local load_scale = CreateFrame("FRAME")
  load_scale:RegisterEvent("ADDON_LOADED")
  load_scale:SetScript("OnEvent", function(_,event)
	if event == "ADDON_LOADED" then
		if playerscale == nil then
		playerscale = scale_default
		end
		SendAddonMessage("oUF D3", "Scale Changed", "WHISPER", UnitName("player"))
	end
  end)
  
  --target and castbar scale
  local targetscale = 0.75  
  --focus, focustarget, pet and partyscale
  local focusscale = 0.5
  
  --TAGS
  --local targetframe_health_tag = "[d3o2abshp] / [perhp]%"
  --local targetframe_health_tag = "[d3o2abshp]/[d3o2maxhp] | [perhp]%"
  --local targetframe_power_tag = "[d3o2absmp] / [perpp]%"
  --local targetframe_power_tag = "[d3o2absmp]"
  
  --activate this if you want to use rbottombarstyler
  --rember that you need to use jExp2 instead of jExp too. 
  local use_rbottombarstyler = 0
  
  --animated portraits yes/no
  local use_3dportraits = 0
  
  --use castbar latency area 0/1
  local use_castbar_latency_zone = 0
  
  --automatic mana detection on stance/class (only works with glows active)
  local automana = 1
  
  --activate the galaxy glow
  local usegalaxy = 1

  --activate the orb m2-file glow
  local useglow = 0
  
  --variable to lighten the orb glow. the higher the value, the lighter the glow gets.
  local fog_smoother = 1
  
  --variable to switch the bar colors
  --0 = grey to red, 1 = red to grey
  local color_switcher = 0
  
  --hide party in raids yes/no
  local hidepartyinraid = 1
  
  --rColors integration
    rFACTION_BAR_COLORS = {
    [1] = {r = 0.8, g = 0.3, b = 0.22},
    [2] = {r = 0.8, g = 0.3, b = 0.22},
    [3] = {r = 0.75, g = 0.27, b = 0},
    [4] = {r = 0.9, g = 0.7, b = 0},
    [5] = {r = 0, g = 0.6, b = 0.1},
    [6] = {r = 0, g = 0.6, b = 0.1},
    [7] = {r = 0, g = 0.6, b = 0.1},
    [8] = {r = 0, g = 0.6, b = 0.1},
  };
  
  rPowerBarColor = {}  
  rPowerBarColor["MANA"] = { r = 0, g = 0.6, b = 1 };
  rPowerBarColor["RAGE"] = { r = 1.00, g = 0.00, b = 0.00 };
  rPowerBarColor["FOCUS"] = { r = 1.00, g = 0.50, b = 0.25 };
  rPowerBarColor["ENERGY"] = { r = 1.00, g = 1.00, b = 0.00 };
  rPowerBarColor["HAPPINESS"] = { r = 0.00, g = 1.00, b = 1.00 };
  rPowerBarColor["RUNES"] = { r = 0.50, g = 0.50, b = 0.50 };
  rPowerBarColor["RUNIC_POWER"] = { r = 0.00, g = 0.82, b = 1.00 };
  -- vehicle colors
  rPowerBarColor["AMMOSLOT"] = { r = 0.80, g = 0.60, b = 0.00 };
  rPowerBarColor["FUEL"] = { r = 0.0, g = 0.55, b = 0.5 };
  
  rRAID_CLASS_COLORS = {
    ["HUNTER"] = { r = 0.67, g = 0.83, b = 0.45 },
    ["WARLOCK"] = { r = 0.58, g = 0.51, b = 0.79 },
    ["PRIEST"] = { r = 1.0, g = 1.0, b = 1.0 },
    ["PALADIN"] = { r = 0.96, g = 0.55, b = 0.73 },
    ["MAGE"] = { r = 0.41, g = 0.8, b = 0.94 },
    ["ROGUE"] = { r = 1.0, g = 0.96, b = 0.41 },
    ["DRUID"] = { r = 1.0, g = 0.49, b = 0.04 },
    ["SHAMAN"] = { r = 0.14, g = 0.35, b = 1.0 },
    ["WARRIOR"] = { r = 0.78, g = 0.61, b = 0.43 },
    ["DEATHKNIGHT"] = { r = 0.77, g = 0.12 , b = 0.23 },
  };
  
  
  rGameTooltip_UnitColor = function(unit)
    local r, g, b;
    if (UnitIsPlayer(unit)) then
      local _, englishClass = UnitClass(unit)
      r = rRAID_CLASS_COLORS[englishClass].r;
      g = rRAID_CLASS_COLORS[englishClass].g;
      b = rRAID_CLASS_COLORS[englishClass].b;
    elseif ( UnitPlayerControlled(unit) ) then
      if ( UnitCanAttack(unit, "player") ) then
        -- Hostile players are red
        if ( not UnitCanAttack("player", unit) ) then
          r = 1.0;
          g = 0;
          b = 1.0;
        else
          r = rFACTION_BAR_COLORS[2].r;
          g = rFACTION_BAR_COLORS[2].g;
          b = rFACTION_BAR_COLORS[2].b;
        end
      elseif ( UnitCanAttack("player", unit) ) then
        -- Players we can attack but which are not hostile are yellow
        r = rFACTION_BAR_COLORS[4].r;
        g = rFACTION_BAR_COLORS[4].g;
        b = rFACTION_BAR_COLORS[4].b;
      elseif ( UnitIsPVP(unit) ) then
        -- Players we can assist but are PvP flagged are green
        r = rFACTION_BAR_COLORS[6].r;
        g = rFACTION_BAR_COLORS[6].g;
        b = rFACTION_BAR_COLORS[6].b;
      else
        r = 1.0;
        g = 0;
        b = 1.0;
      end
    else
      local reaction = UnitReaction(unit, "player");
      if ( reaction ) then
        r = rFACTION_BAR_COLORS[reaction].r;
        g = rFACTION_BAR_COLORS[reaction].g;
        b = rFACTION_BAR_COLORS[reaction].b;
      else
        r = 1.0;
        g = 0;
        b = 1.0;
      end
    end
    return r, g, b;
  end

  GameTooltip_UnitColor = rGameTooltip_UnitColor;
  UnitSelectionColor = GameTooltip_UnitColor
  
  --oUF smooth integration
  if not oUF then return end

local smoothing = {}
local function Smooth(self, value)
	if value ~= self:GetValue() or value == 0 then
		smoothing[self] = value
	else
		smoothing[self] = nil
	end
end

local function SmoothBar(self, bar)
	bar.SetValue_ = bar.SetValue
	bar.SetValue = Smooth
end

local function hook(frame)
	frame.SmoothBar = SmoothBar
	if frame.Health and frame.Health.Smooth then
		frame:SmoothBar(frame.Health)
	end
	if frame.Power and frame.Power.Smooth then
		frame:SmoothBar(frame.Power)
	end
end


for i, frame in ipairs(oUF.objects) do hook(frame) end
oUF:RegisterInitCallback(hook)


local f, min, max = CreateFrame("Frame"), math.min, math.max
f:SetScript("OnUpdate", function()
	local limit = 30/GetFramerate()
	for bar, value in pairs(smoothing) do
		local cur = bar:GetValue()
		local barmin, barmax = bar:GetMinMaxValues()
		local new = cur + min((value-cur)/20, max(value-cur, limit))
		if new ~= new then
			new = value
		end
		bar:SetValue_(new)
    if bar.Filling then
      if barmax == 0 then
        bar.Filling:SetHeight(0)
        bar.Filling:SetTexCoord(0,1,1,1)
      else
        bar.Filling:SetHeight((new / barmax) * bar:GetWidth())
        bar.Filling:SetTexCoord(0,1,  math.abs(new / barmax - 1),1)
      end
    end
		if cur == value or abs(cur - value) < 2 then
			bar:SetValue_(value)
			smoothing[bar] = nil
		end
	end
end)

--
  -- healthcolor defines what healthcolor will be used
  -- 0 = class color, 1 = red, 2 = green, 3 = blue, 4 = yellow, 5 = runic
 --local healthcolor = 0
   
  -- manacolor defines what manacolor will be used
  -- 1 = red, 2 = green, 3 = blue, 4 = yellow, 5 = runic
 --local manacolor = 3
  
  --combatColor defines what color the orb will change to in combat
  -- 1 = red(default), 2 = green, 3 = blue, 4 = yellow, 5 = runic
 --local combatColor = 1
  local function set_d3_colors()
  --local set_mana_color, set_health_color, set_combat_color;
 --select mana color type
 --select health color type
	if set_health_color == nil then
		healthcolor = 0
	else
		healthcolor = set_health_color
	end
	--select combat color type
	if set_combat_color == nil then
		combatColor = 1
	else
		combatColor = set_combat_color
	end
end -- end of set_d3_colors func

set_d3_colors() -- load set_colors once
	
  
  -- usebar defines what actionbar texture will be used. 
  -- not really needed anymore, 36 texture will only be used if MultiBarRight is shown
  -- usebar = 1 -> choose automatically
  -- usebar = 2 -> 12 button texture always
  -- usebar = 3 -> 24 button texture always
  -- usebar = 4 -> 36 button texture always
  local usebar = 3
  
  local player_class_color = rRAID_CLASS_COLORS[select(2, UnitClass("player"))]
  
  local orbtab = {
    [0] = {r = player_class_color.r*0.8, g = player_class_color.g*0.8,   b = player_class_color.b*0.8, scale = 0.9, z = -12, x = -0.5, y = -0.8, anim = "SPELLS\\WhiteRadiationFog.m2"}, -- class color
    [1] = {r = 0.8, g = 0, b = 0, scale = 0.8, z = -12, x = 0.8, y = -1.7, anim = "SPELLS\\RedRadiationFog.m2"}, -- red
    [2] = {r = 0.2, g = 0.8, b = 0, scale = 0.75, z = -12, x = 0, y = -1.1, anim = "SPELLS\\GreenRadiationFog.m2"}, -- green
    [3] = {r = 0, g = 0.35,   b = 0.9, scale = 0.75, z = -12, x = 1.2, y = -1, anim = "SPELLS\\BlueRadiationFog.m2"}, -- blue
    [4] = {r = 0.9, g = 0.7, b = 0.1, scale = 0.75, z = -12, x = -0.3, y = -1.2, anim = "SPELLS\\OrangeRadiationFog.m2"}, -- yellow
    [5] = {r = 0.1, g = 0.8,   b = 0.7, scale = 0.9, z = -12, x = -0.5, y = -0.8, anim = "SPELLS\\WhiteRadiationFog.m2"}, -- runic
	[6] = {r = 0.58, g = 0.51, b = 0.79, scale = 0.8, z=-12, x=0.8, y=-1.7, anim= "SPELLS\\WhiteRadiationFog.m2"}, -- warlock purple
	[7] = {r = 1.0, g = 1.0, b = 1.0 , scale = 0.8, z=-12, x=0.8, y=-1.7, anim= "SPELLS\\WhiteRadiationFog.m2"}, -- priest white
	[8] = {r = 0.96, g = 0.55, b = 0.73 , scale = 0.8, z=-12, x=0.8, y=-1.7, anim="SPELLS\\WhiteRadiationFog.m2"}, -- paladin pink
	[9] = {r = 1.0, g = 0.12, b = 0.04 , scale = 0.8, z=-12, x=0.8, y=-1.7, anim="SPELLS\\WhiteRadiationFog.m2"}, -- druid orange
	[10] = {r = 0.78, g = 0.61, b = 0.43, scale = 0.8, z=-12, x=0.8, y=-1.7, anim="SPELLS\\WhiteRadiationFog.m2"}, -- warrior tan
	[11] = {r = 1.1, g = 0.5, b = 0.25 , scale = 0.8, z=-12, x=0.8, y=-1.7, anim="SPELLS\\WhiteRadiationFog.m2"}, -- focus orange
    [12] = {r = 0.8, g = 0, b = 0, scale = 0.8, z = -12, x = 0.8, y = -1.7, anim= "SPELLS\\RedRadiationFog.m2"} -- combat red
 }
  
  local galaxytab = {
    [0] = {r = player_class_color.r, g = player_class_color.g, b = player_class_color.b, }, -- class color
    [1] = {r = 0.90, g = 0.1, b = 0.1, }, -- red
    [2] = {r = 0.25, g = 0.9, b = 0.25, }, -- green
    [3] = {r = 0, g = 0.35,   b = 0.9, }, -- blue
    [4] = {r = 0.9, g = 0.8, b = 0.35, }, -- yellow
    [5] = {r = 0.35, g = 0.9,   b = 0.9, }, -- runic
	[6] = {r = 0.58, g = 0.51, b = 0.79, }, -- warlock purple
	[7] = {r = 1.0, g = 1.0, b = 1.0, }, --priest white
	[8] = {r = 0.96, g = 0.55, b = 0.73, }, -- paladin pink
	[9] = {r = 1.0, g = 0.49, b = 0.04, }, -- druid orange
	[10] = {r = 0.78, g = 0.61, b = 0.43 , }, -- warrior tan
	[11] = {r = 1.0, g = 0.5, b = 0.25 , }, -- focus orange
	[12] = {r = 0.8, g = 0, b = 0, } -- combat red
  }
  
  local orbfilling_texture = "orb_filling1"
  local statusbar128 = "Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\statusbar128"
  local statusbar256 = "Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\statusbar256"

  local tabvalues = {
    power = {
      [-2] = rPowerBarColor["AMMO"], -- fuel
      [-1] = rPowerBarColor["FUEL"], -- fuel
      [0] = rPowerBarColor["MANA"], -- Mana
      [1] = rPowerBarColor["RAGE"], -- Rage
      [2] = rPowerBarColor["FOCUS"], -- Focus
      [3] = rPowerBarColor["ENERGY"], -- Energy
      [4] = rPowerBarColor["HAPPINESS"], -- Happiness
      [5] = rPowerBarColor["RUNES"], -- dont know
      [6] = rPowerBarColor["RUNIC_POWER"], -- deathknight
    },
    happiness = {
      [0] = {r = 1, g = 1, b = 1}, -- bla test
      [1] = {r = 1, g = 0, b = 0}, -- need.... | unhappy
      [2] = {r = 1, g = 1, b = 0}, -- new..... | content
      [3] = {r = 0, g = 1, b = 0}, -- colors.. | happy
    },
    frame_positions = {
      [1] =   { a1 = "BOTTOM",  a2 = "BOTTOM",  af = "UIParent",                  x = 260,    y = -9      }, --player mana orb
      [2] =   { a1 = "BOTTOM",  a2 = "BOTTOM",  af = "UIParent",                  x = -260,   y = -9     }, --player health orb
      [3] =   { a1 = "CENTER",  a2 = "CENTER",  af = "UIParent",                  x = 0,      y = -300    }, --target frame
      [4] =   { a1 = "RIGHT",   a2 = "LEFT",    af = "oUF_D3Orbs2_TargetFrame",   x = 410,    y = -70      }, --tot
      [5] =   { a1 = "LEFT",    a2 = "RIGHT",   af = "UIParent",                  x = 50,     y = 100     }, --pet
      [6] =   { a1 = "LEFT",    a2 = "LEFT",    af = "UIParent",                  x = 60,     y = -100    }, --focus
      [7] =   { a1 = "TOPLEFT", a2 = "TOPLEFT", af = "UIParent",                  x = 15,     y = -10     }, --party
      [8] =   { a1 = "BOTTOM",  a2 = "BOTTOM",  af = "UIParent",                  x = 333,    y = 0       }, --angel
      [9] =   { a1 = "BOTTOM",  a2 = "BOTTOM",  af = "UIParent",                  x = -345,   y = 0       }, --demon
      [10] =  { a1 = "BOTTOM",  a2 = "BOTTOM",  af = "UIParent",                  x = 0,      y = -5      }, --botomline texture
      [11] =  { a1 = "BOTTOM",  a2 = "BOTTOM",  af = "UIParent",                  x = 1,      y = 0       }, --bottom bar background texture
      [12] =  { a1 = "CENTER",  a2 = "CENTER",  af = "UIParent",			      x = 0,      y = 100     }, --castbar target
      [13] =  { a1 = "CENTER",  a2 = "CENTER",  af = "UIParent",				  x = 0,      y = -80     },  --castbar player
      [14] =  { a1 = "CENTER",  a2 = "CENTER",  af = "UIParent",				  x = 0,      y = 180     }, --castbar focus
    },
  }
  
	--playervehicle set
  playerinvehicle = 0
  
  local function set_scaling(self, perc)
	if perc < 150 then
		self:SetScale(perc)
	end
  end
  
  --movement functions **mana is not included here - mana's movement function is within the createManaOrb function for container relevency**
    local function make_health_movable(self)
	  self:EnableMouse(true)
	  if allow_frame_movement == 0 then
	  self:SetMovable(false)
	  self:RegisterForDrag(nil, nil)
	  elseif lock_all_frames == 1 then
	  self:RegisterForDrag(nil, nil)
	  else
      self:SetMovable(true)
      self:EnableMouse(true)
      self:RegisterForDrag("LeftButton","RightButton")
      self:SetScript("OnDragStart", function(self) self:StartMoving() end)
      self:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
	  end
    end  
  
	local function make_d3f_movable(self)
	  if allow_frame_movement == 0 then
	  self:SetMovable(false)
	  self:RegisterForDrag(nil, nil)
	  elseif lock_all_frames == 1 then
	  self:EnableMouse(false)
	  self:RegisterForDrag(nil, nil)
	  else
      self:SetMovable(true)
      self:EnableMouse(true)
      self:RegisterForDrag("LeftButton","RightButton")
      self:SetScript("OnDragStart", function(self) self:StartMoving() end)
      self:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
	  end
    end  
	
	local function make_d3f2_movable(self)
	  if allow_frame_movement == 0 then
	  self:SetMovable(false)
	  self:RegisterForDrag(nil, nil)
	  elseif lock_all_frames == 1 then
	  self:EnableMouse(false)
	  self:RegisterForDrag(nil, nil)
	  else
      self:SetMovable(true)
      self:EnableMouse(true)
      self:RegisterForDrag("LeftButton","RightButton")
      self:SetScript("OnDragStart", function(self) self:StartMoving() end)
      self:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
	  end
    end  
	
	local function make_powers_movable(self)
	  if allow_frame_movement == 0 then
	  self:SetMovable(false)
	  self:RegisterForDrag(nil, nil)
	  elseif lock_all_frames == 1 then
	  self:EnableMouse(false)
	  self:RegisterForDrag(nil, nil)
	  else
      self:SetMovable(true)
      self:EnableMouse(true)
      self:RegisterForDrag("LeftButton","RightButton")
      self:SetScript("OnDragStart", function(self) self:StartMoving() end)
      self:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
	  end
	end
	
  -----------------------------
  -- VARIABLES + CONFIG END
  -----------------------------
  
  --position deathknight runes
  RuneButtonIndividual1:ClearAllPoints()
  RuneButtonIndividual1:SetPoint("BOTTOM", UIParent, "BOTTOM", -55, 140)

  --disable the pet castbar (for vehicles!)
  PetCastingBarFrame:UnregisterAllEvents()
  PetCastingBarFrame.Show = function() end
  PetCastingBarFrame:Hide()
  
  -----------------------------
  -- FUNCTIONS
  -----------------------------
  --chat output func
  local function am(text)
    DEFAULT_CHAT_FRAME:AddMessage(text)
  end
  
  --automana
  local function set_automana()
    if automana == 1 then
      local st = GetShapeshiftForm()
      if myclass == "WARRIOR" then
		if set_mana_color == nil then
		   manacolor = 1
		else
		   manacolor = set_mana_color
		end
      elseif myclass == "DEATHKNIGHT" then
		if set_mana_color == nil then
		    manacolor = 5
		else
			manacolor = set_mana_color
		end
      elseif myclass == "HUNTER" then
		if set_mana_color == nil then
			manacolor = 11
	    else
			manacolor = set_mana_color
	  end
      elseif myclass == "ROGUE" then
		if set_mana_color == nil then
			manacolor = 4
		else
			manacolor = set_mana_color
		end
	  elseif myclass == "DRUID" and st == 1 and IsUsableSpell("Cat Form") and not IsUsableSpell("Bear Form") and not IsUsableSpell("Aquatic Form") then
		if set_kitty_mana == nil then
			manacolor = 4
		else
			manacolor = set_kitty_mana
		end
		elseif myclass == "DRUID" and st == 2 and IsUsableSpell("Bear Form") and not IsUsableSpell("Aquatic Form") then
		if set_kitty_mana == nil then
			manacolor = 4
		else
			manacolor = set_kitty_mana
		end
	  elseif myclass == "DRUID" and st == 1 and IsUsableSpell("Bear Form") and not IsUsableSpell("Aquatic Form") then
		if set_bear_mana == nil then
			manacolor = 1
		else
			manacolor = set_bear_mana
		end
	  elseif myclass == "DRUID" and st == 3 then
		if set_kitty_mana == nil then
			manacolor = 4
		else
        manacolor = set_kitty_mana
		end
      elseif myclass == "DRUID" and st == 1 then
		if set_bear_mana == nil then
			manacolor = 1
		else
		manacolor = set_bear_mana
		end
	  elseif set_mana_color == nil then
		manacolor = 3
	  else 
		manacolor = set_mana_color
	  end
	 end
  end
  --call it once
  set_automana()
  
  --check function for vehicle manatype
  local function set_vehicle_mana(self)
    self.Power.Filling:SetVertexColor(orbtab[manacolor].r,orbtab[manacolor].g,orbtab[manacolor].b)
    if usegalaxy == 1 then
      self.gal4.t:SetVertexColor(galaxytab[manacolor].r,galaxytab[manacolor].g,galaxytab[manacolor].b)
      self.gal5.t:SetVertexColor(galaxytab[manacolor].r,galaxytab[manacolor].g,galaxytab[manacolor].b)
      self.gal6.t:SetVertexColor(galaxytab[manacolor].r,galaxytab[manacolor].g,galaxytab[manacolor].b)
    elseif useglow == 1 then
      self.pm3:SetModel(orbtab[manacolor].anim)
      self.pm3:SetModelScale(orbtab[manacolor].scale)
      self.pm3:SetPosition(orbtab[manacolor].z, orbtab[manacolor].x, orbtab[manacolor].y) 
      self.pm4:SetModel(orbtab[manacolor].anim)
      self.pm4:SetModelScale(orbtab[manacolor].scale)
      self.pm4:SetPosition(orbtab[manacolor].z, orbtab[manacolor].x, orbtab[manacolor].y+1)       
    end
  end
  
  --set function for health color in/out of combat, called by d3o2_createOrb
  local function set_combat_health(self)
	self.gal1.t:SetVertexColor(galaxytab[combatColor].r,galaxytab[combatColor].g,galaxytab[combatColor].b)
    self.gal2.t:SetVertexColor(galaxytab[combatColor].r,galaxytab[combatColor].g,galaxytab[combatColor].b)
    self.gal3.t:SetVertexColor(galaxytab[combatColor].r,galaxytab[combatColor].g,galaxytab[combatColor].b) 
	self.Health.Filling:SetVertexColor(orbtab[combatColor].r,orbtab[combatColor].g,orbtab[combatColor].b)
  end
  
  local function set_standard_health(self)
	self.gal1.t:SetVertexColor(galaxytab[healthcolor].r,galaxytab[healthcolor].g,galaxytab[healthcolor].b)
    self.gal2.t:SetVertexColor(galaxytab[healthcolor].r,galaxytab[healthcolor].g,galaxytab[healthcolor].b)
    self.gal3.t:SetVertexColor(galaxytab[healthcolor].r,galaxytab[healthcolor].g,galaxytab[healthcolor].b) 
	self.Health.Filling:SetVertexColor(orbtab[healthcolor].r,orbtab[healthcolor].g,orbtab[healthcolor].b)
  end
  
  --check function for druid manatype ******** Added functionality to determine whether or not the target is in combat ***********
  local function check_druid_mana(self,event)
    local st = GetShapeshiftForm()
    if st ~= dudustance then
      set_automana()
      set_vehicle_mana(self)
      dudustance = st
    end
	if event == "PLAYER_REGEN_DISABLED" then
		if set_combat_color == nil then
			if myclass == "DEATHKNIGHT" then
			combatColor = 5
			else
			combatColor = 1
			end
		else
		combatColor = set_combat_color
		end
		set_combat_health(self)
	elseif event == "PLAYER_REGEN_ENABLED" then
		if set_health_color == nil then
			healthcolor = 0 
		else
		healthcolor = set_health_color
		end
		set_standard_health(self)
	elseif event == "ADDON_LOADED" then
		if set_health_color == nil then
			healthcolor = 0
		else
		healthcolor = set_health_color
		end
		set_automana()
		set_vehicle_mana(self)
		set_standard_health(self)
	elseif event == "CHAT_MSG_ADDON" and stringcheck == "changed" then
		set_automana()
		set_vehicle_mana(self)
		set_standard_health(self)
		stringcheck = "reset"
	end
  end
  
  --do format func
  local function do_format(v)
    local string = ""
    if v > 1000000 then
      string = (floor((v/1000000)*10)/10).."m"
    elseif v > 100000 then
      string = (floor((v/1000)*10)/10).."k"
    else
      string = v
    end  
    return string
  end
  
  --update player health func
  local function d3o2_updatePlayerHealth(self, event, unit, bar, min, max)
    local d = floor(min/max*100)
    self.Health.Filling:SetHeight((min / max) * self.Health:GetWidth())
    self.Health.Filling:SetTexCoord(0,1,  math.abs(min / max - 1),1)
    if useglow == 1 then
      self.pm1:SetAlpha((min/max)/fog_smoother)
      self.pm2:SetAlpha((min/max)/fog_smoother)
    end
    if usegalaxy == 1 then
      self.gal1:SetAlpha(min/max)
      self.gal2:SetAlpha(min/max)
      self.gal3:SetAlpha(min/max)
    end
    if d <= 25 and min > 1 then
      self.LowHP:Show()
    else
      self.LowHP:Hide()
    end
  end
  
  --update player power func
  local function d3o2_updatePlayerPower(self, event, unit, bar, min, max)
    local d, d2
    if max == 0 then
      d = 0
      d2 = 0
    else
     d = min/max
     d2 = floor(min/max*100)
    end
    self.Power.Filling:SetHeight((d) * self.Power:GetWidth())
    self.Power.Filling:SetTexCoord(0,1,  math.abs(d - 1),1)
    if useglow == 1 then
      self.pm3:SetAlpha((d)/fog_smoother)
      self.pm4:SetAlpha((d)/fog_smoother)
    end
    if usegalaxy == 1 then
      self.gal4:SetAlpha(d)
      self.gal5:SetAlpha(d)
      self.gal6:SetAlpha(d)
    end
    
    local shape
    if myclass == "DRUID" then
      shape = GetShapeshiftForm()    
    end  
    
    if myclass == "WARRIOR" or (myclass == "DRUID" and shape == 3) or (myclass == "DRUID" and shape == 1) or myclass == "DEATHKNIGHT" or myclass == "ROGUE" then
      self.mpval1:SetText(do_format(min))
      self.mpval2:SetText(d2)
    else
      self.mpval1:SetText(d2)
      self.mpval2:SetText(do_format(min))
    end
    
    if playerinvehicle == 1 then
      local pt = UnitPowerType("pet");
      if pt then
        if pt ~= vehiclepower then
          --am("ping"..pt)
          vehiclepower = pt
          if pt == 1 then
            manacolor = 1
          elseif pt == 3 then
            manacolor = 4
          else
            manacolor = 3
          end
          set_vehicle_mana(self)
        end        
      end      
    end
    
  end
  
  --update health func
  local function d3o2_updateHealth(self, event, unit, bar, min, max)
    local d = floor(min/max*100)
    local color
    local dead
    if UnitIsDeadOrGhost(unit) == 1 or UnitIsConnected(unit) == nil then
      color = {r = 0.4, g = 0.4, b = 0.4}
      dead = 1
    elseif UnitIsPlayer(unit) then
      if rRAID_CLASS_COLORS[select(2, UnitClass(unit))] then
        color = rRAID_CLASS_COLORS[select(2, UnitClass(unit))]
      end
    elseif unit == "pet" and UnitExists("pet") and GetPetHappiness() then
      local happiness = GetPetHappiness()
      color = tabvalues.happiness[happiness]
      self.Name:SetText(UnitName(unit))
    else
      color = rFACTION_BAR_COLORS[UnitReaction(unit, "player")]
    end

    if color_switcher == 1 then
      bar:SetStatusBarColor(0.7,0,0,1)
      bar.bg:SetVertexColor(0.15,0.15,0.15,1)
    else
      bar:SetStatusBarColor(0.15,0.15,0.15,1)
      bar.bg:SetVertexColor(0.7,0,0,1)
    end
    
    --if you like color colored background, use this
    --bar.bg:SetVertexColor(color.r, color.g, color.b,1)
    if dead == 1 then
      bar.bg:SetVertexColor(0,0,0,0)  
    end
    if color then
      self.Name:SetTextColor(color.r, color.g, color.b,1)
    end
    if d <= 25 and min > 1 then
      self.LowHP:Show()
    else
      self.LowHP:Hide()
    end
  end
  
  --update power func
  local function d3o2_updatePower(self, event, unit, bar, min, max)
    --if max == 0 then
    --  bar:SetAlpha(0)
    --else
    --  bar:SetAlpha(1)
      local color = tabvalues.power[UnitPowerType(unit)]
      bar:SetStatusBarColor(color.r, color.g, color.b,1)
      bar.bg:SetVertexColor(color.r*0.3, color.g*0.3, color.b*0.3,1)
    --end
  end

  --menu  
  local function menu(self)
    local unit = self.unit:sub(1, -2)
    local cunit = self.unit:gsub("(.)", string.upper, 1)
    if(unit == "party" or unit == "partypet") then
      ToggleDropDownMenu(1, nil, _G["PartyMemberFrame"..self.id.."DropDown"], "cursor", 0, 0)
    elseif(_G[cunit.."FrameDropDown"]) then
      ToggleDropDownMenu(1, nil, _G[cunit.."FrameDropDown"], "cursor", 0, 0)
    end
  end
  
  --setup frame width, height, strata
  local function d3o2_setupFrame(self,w,h,strata)
    self.menu = menu
    self:RegisterForClicks("AnyUp")
    self:SetAttribute("*type2", "menu")
    self:SetScript("OnEnter", UnitFrame_OnEnter)
    self:SetScript("OnLeave", UnitFrame_OnLeave)
    if strata == "BACKGROUND" then
      self:SetFrameStrata(strata)
    end
    --self:SetWidth(w)
    --self:SetHeight(h)
    self:SetAttribute("initial-height", h)
	  self:SetAttribute("initial-width", self.width)
  end
  
  --orb glow func
  local function create_me_a_orb_glow(f,type,pos)
    local glow = CreateFrame("PlayerModel", nil, f)
    glow:SetFrameStrata("BACKGROUND")
    glow:SetFrameLevel(5)
    glow:SetAllPoints(f)
    if type == "power" then
      glow:SetModel(orbtab[manacolor].anim)
      glow:SetModelScale(orbtab[manacolor].scale)
      glow:SetPosition(orbtab[manacolor].z, orbtab[manacolor].x, orbtab[manacolor].y+pos) 
      glow:SetAlpha(1/fog_smoother)
      glow:SetScript("OnShow",function() 
        glow:SetModel(orbtab[manacolor].anim)
        glow:SetModelScale(orbtab[manacolor].scale)
        glow:SetPosition(orbtab[manacolor].z, orbtab[manacolor].x, orbtab[manacolor].y+pos) 
      end)
    else
      glow:SetModel(orbtab[healthcolor].anim)
      --glow:SetModelScale(orbtab[healthcolor].scale)
      --glow:SetPosition(orbtab[healthcolor].z, orbtab[healthcolor].x, orbtab[healthcolor].y+pos) 
      glow:SetAlpha(1/fog_smoother)
      glow:SetScript("OnShow",function() 
        glow:SetModel(orbtab[healthcolor].anim)
        glow:SetModelScale(orbtab[healthcolor].scale)
        glow:SetPosition(orbtab[healthcolor].z, orbtab[healthcolor].x, orbtab[healthcolor].y+pos) 
      end)    
    end
    return glow
  end
  
  local function create_me_a_galaxy(f,type,x,y,size,alpha,dur,tex)
    local h = CreateFrame("Frame",nil,f)
    h:SetHeight(size)
    h:SetWidth(size)		  
    h:SetPoint("CENTER",x,y)
    h:SetAlpha(alpha)
    h:SetFrameLevel(3)
  
    local t = h:CreateTexture()
    t:SetAllPoints(h)
    t:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\"..tex)
    t:SetBlendMode("ADD")
    if type == "power" then
      t:SetVertexColor(galaxytab[manacolor].r,galaxytab[manacolor].g,galaxytab[manacolor].b)
    else
      t:SetVertexColor(galaxytab[healthcolor].r,galaxytab[healthcolor].g,galaxytab[healthcolor].b)
    end
    h.t = t
    
    local ag = h:CreateAnimationGroup()
    h.ag = ag
    
    local a1 = h.ag:CreateAnimation("Rotation")
    a1:SetDegrees(360)
    a1:SetDuration(dur)
    h.ag.a1 = a1
    
    h.ag:Play()
    h.ag:SetLooping("REPEAT")
    
    return h
  
  end
  

  
  --check vehicle type
  local function check_vehicle_mana(self,event)
	if event == "UNIT_ENTERED_VEHICLE" then
      playerinvehicle = 1
    else
		playerinvehicle = 0
		vehiclepower = nil
		set_automana()
		set_vehicle_mana(self)
    end
  end
   
   --create health orb func
  local function d3o2_createHealthOrb(self, type)
   local orb
   orb = CreateFrame("StatusBar", nil, self)
   orb:SetStatusBarTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_transparent.tga")
   orb:SetHeight(orbsize)
   orb:SetWidth(orbsize)
   orb.bg = orb:CreateTexture(nil, "BACKGROUND")
   orb.bg:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_back2.tga")
   orb.bg:SetAllPoints(orb)
   orb.Filling = orb:CreateTexture(nil, "ARTWORK")
   orb.Filling:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\"..orbfilling_texture)
   orb.Filling:SetPoint("BOTTOMLEFT",0,0)
   orb.Filling:SetWidth(orbsize)
   orb.Filling:SetHeight(orbsize)
   --orb.Filling:SetBlendMode("add")
   orb.Filling:SetAlpha(1)
   orbGlossHolder = CreateFrame("Frame", nil, orb)
   orbGlossHolder:SetAllPoints(orb)
   orbGlossHolder:SetFrameStrata("LOW")
   orbOrbGloss = orbGlossHolder:CreateTexture(nil, "OVERLAY")
   orbOrbGloss:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_gloss.tga")
   orbOrbGloss:SetAllPoints(orbGlossHolder)
   orb:SetPoint("TOPLEFT", 0, 0)
   self.Health = orb
   self.Health.Filling = orb.Filling
	--added this function to change the color of the health orb if the player is in combat
      if usegalaxy == 1 then
        self.gal1 = create_me_a_galaxy(orb,type,0,-5,orbsize-10,1,58,"galaxy2")
        self.gal2 = create_me_a_galaxy(orb,type,5,-10,orbsize-10,1,29,"galaxy")
        self.gal3 = create_me_a_galaxy(orb,type,-5,-15,orbsize-0,1,16,"galaxy3")
        self.Health.Filling:SetVertexColor(orbtab[healthcolor].r,orbtab[healthcolor].g,orbtab[healthcolor].b)
      elseif useglow == 1 then
        self.pm1 = create_me_a_orb_glow(orb,type,0)
        self.pm2 = create_me_a_orb_glow(orb,type,1)
        self.Health.Filling:SetVertexColor(orbtab[healthcolor].r,orbtab[healthcolor].g,orbtab[healthcolor].b)
      else
        self.Health.Filling:SetVertexColor(0.5,1,0)
      end
      self.Health.Smooth = true
	  orb:Show()
   end
   
	--create mana orb func
  local function d3o2_createManaOrb(self,type)
    local orb
    orb = CreateFrame("StatusBar", "oUF_D3Orbs2_PlayerManaOrb", self)
    orb:SetStatusBarTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_transparent.tga")
    orb:SetHeight(orbsize)
    orb:SetWidth(orbsize)
    orb.bg = orb:CreateTexture(nil, "BACKGROUND")
    orb.bg:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_back2.tga")
    orb.bg:SetAllPoints(orb)
    orb.Filling = orb:CreateTexture(nil, "ARTWORK")
    orb.Filling:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\"..orbfilling_texture)
    orb.Filling:SetPoint("BOTTOMLEFT",0,0)
    orb.Filling:SetWidth(orbsize)
    orb.Filling:SetHeight(orbsize)
    --orb.Filling:SetBlendMode("add")
    orb.Filling:SetAlpha(1)
    orbGlossHolder = CreateFrame("Frame", nil, orb)
    orbGlossHolder:SetAllPoints(orb)
    orbGlossHolder:SetFrameStrata("LOW")
    orbOrbGloss = orbGlossHolder:CreateTexture(nil, "OVERLAY")
    orbOrbGloss:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_gloss.tga")
    orbOrbGloss:SetAllPoints(orbGlossHolder)
	self.Power = orb
	  self.Power:SetPoint(tabvalues.frame_positions[1].a1, tabvalues.frame_positions[1].af, tabvalues.frame_positions[1].a2, tabvalues.frame_positions[1].x, tabvalues.frame_positions[1].y)
	  self.Power:SetMovable(true)	
	  self.Power:EnableMouse(true)
	  self.Power:RegisterForDrag(true)
	  self.Power:SetScript("OnDragStart", function(self) self:StartMoving() end)
	  self.Power:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
      self.Power.Filling = orb.Filling
      if usegalaxy == 1 then
        self.gal4 = create_me_a_galaxy(orb,type,0,-5,orbsize-10,1,60,"galaxy2")
        self.gal5 = create_me_a_galaxy(orb,type,-5,-10,orbsize-10,1,30,"galaxy")
        self.gal6 = create_me_a_galaxy(orb,type,5,-15,orbsize-0,1,15,"galaxy3")
        self.Power.Filling:SetVertexColor(orbtab[manacolor].r,orbtab[manacolor].g,orbtab[manacolor].b)
        if myclass == "DRUID" and automana == 1 then
          self.Power:RegisterEvent("PLAYER_ENTERING_WORLD")
          self.Power:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
		  self.Power:SetScript("OnEvent", function(_,event)
            check_druid_mana(self, event)  
	       end)
        end
        if automana == 1 then
          orbGlossHolder:RegisterEvent("UNIT_ENTERED_VEHICLE")
          orbGlossHolder:RegisterEvent("UNIT_EXITED_VEHICLE")
		  orbGlossHolder:RegisterEvent("ADDON_LOADED")
		  orbGlossHolder:RegisterEvent("CHAT_MSG_ADDON")
		  orbGlossHolder:SetScript("OnEvent", function(_,event,arg1)
            if arg1 == "player" then
              check_vehicle_mana(self,event)
            else
			  check_druid_mana(self,event)
			end
			if event == "CHAT_MSG_ADDON" and arg1 == "oUF D3" then
				if lock_all_frames == 0 then
					self.Power:RegisterForDrag("LeftButton", "RightButton")
				elseif lock_all_frames == 1 then
					self.Power:RegisterForDrag(nil, nil)
				end
				if orbPos_altered == nil then
					self.Power:ClearAllPoints()
					self.Power:SetPoint("BOTTOM", nil, "BOTTOM", 260, -9)	
				end
			end
          end)
		  orb:Show()
        end
      elseif useglow == 1 then
        self.pm3 = create_me_a_orb_glow(orb,type,0)
        self.pm4 = create_me_a_orb_glow(orb,type,1)
        self.Power.Filling:SetVertexColor(orbtab[manacolor].r,orbtab[manacolor].g,orbtab[manacolor].b)
        if myclass == "DRUID" and automana == 1 then
          self.Power:RegisterEvent("PLAYER_ENTERING_WORLD")
          self.Power:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
		  self.Power:SetScript("OnEvent", function(_,event)
			check_druid_mana(self, event)  
	      end)
        end
        if automana == 1 then
          orbGlossHolder:RegisterEvent("UNIT_ENTERED_VEHICLE")
          orbGlossHolder:RegisterEvent("UNIT_EXITED_VEHICLE")
		  orbGlossHolder:SetScript("OnEvent", function(_,event,arg1)
            if arg1 == "player" then
              check_vehicle_mana(self,event)
            end
          end)
        end
      else
        self.Power.Filling:SetVertexColor(0,0.5,1)
      end
      self.Power.frequentUpdates = true
      self.Power.Smooth = true
    end
  

  --set fontstring
  local function SetFontString(parent, fontName, fontHeight, fontStyle)
    local fs = parent:CreateFontString(nil, "OVERLAY")
    fs:SetFont(fontName, fontHeight, fontStyle)
    fs:SetShadowColor(0,0,0,1)
    return fs
  end
  
  --create health and power bar func for every frame but not player
  local function d3o2_createHealthPowerFrames(self,unit)
    --health
    self.Health = CreateFrame("StatusBar", nil, self)
    if unit == "target" then
      self.Health:SetStatusBarTexture(statusbar256)
    else
      self.Health:SetStatusBarTexture(statusbar128)
    end
    self.Health:SetHeight(16)
    self.Health:SetWidth(self.width)
    if unit == "target" or unit == "targettarget" then
      self.Health:SetPoint("TOPLEFT",0,-1)
    else
      self.Health:SetPoint("BOTTOMLEFT",0,1)
    end      
    if unit == "target" then
      self.bg = self:CreateTexture(nil, "BACKGROUND")
      self.bg:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_targetframe.tga")
      self.bg:SetWidth(512)
      self.bg:SetHeight(128)
      self.bg:SetPoint("CENTER",-3,0)
      self.Health.bg = self.Health:CreateTexture(nil, "BACKGROUND")
      self.Health.bg:SetTexture(statusbar256)
      self.Health.bg:SetAllPoints(self.Health)    
    elseif unit == "targettarget" then
      self.bg = self:CreateTexture(nil, "BACKGROUND")
      self.bg:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3totframe.tga")
      self.bg:SetWidth(256)
      self.bg:SetHeight(128)
      self.bg:SetPoint("CENTER",-2,0)
      self.Health.bg = self.Health:CreateTexture(nil, "BACKGROUND")
      self.Health.bg:SetTexture(statusbar128)
      self.Health.bg:SetAllPoints(self.Health)
    else
      self.bg = self:CreateTexture(nil, "BACKGROUND")
      self.bg:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3totframe.tga")
      self.bg:SetWidth(256)
      self.bg:SetHeight(128)
      self.bg:SetPoint("BOTTOM",-2,-56)
      self.Health.bg = self.Health:CreateTexture(nil, "BACKGROUND")
      self.Health.bg:SetTexture(statusbar128)
      self.Health.bg:SetAllPoints(self.Health)    
    end  
    self.Health.Smooth = true
    --power    
    self.Power = CreateFrame("StatusBar", nil, self)
    if unit == "target" then
      self.Power:SetStatusBarTexture(statusbar256)
    else
      self.Power:SetStatusBarTexture(statusbar128)
    end
    self.Power:SetHeight(4)
    self.Power:SetWidth(self.width)
    self.Power:SetPoint("TOP", self.Health, "BOTTOM", 0, 0)
    self.Power.bg = self.Power:CreateTexture(nil, "BACKGROUND")
    if unit == "target" then
      self.Power.bg:SetTexture(statusbar256)
    else
      self.Power.bg:SetTexture(statusbar128)
    end
    self.Power.bg:SetAllPoints(self.Power)
    self.Power.Smooth = true
    if unit == "pet" then
      self.Power.frequentUpdates = true
    end
  end
  
  --aura icon func
  local function d3o2_createAuraIcon(self, button, icons, index, debuff)
    button.cd:SetReverse()
    button.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
    button.count:SetPoint("BOTTOMRIGHT", button, 2, -2)
    button.count:SetTextColor(0.7,0.7,0.7)
    --fix the count on aurawatch, make the count fontsize button size dependend
    button.count:SetFont(d3font,button:GetWidth()/1.5,"THINOUTLINE")
    self.ButtonOverlay = button:CreateTexture(nil, "OVERLAY")
    self.ButtonOverlay:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\gloss2.tga")
    self.ButtonOverlay:SetVertexColor(0.37,0.3,0.3,1);
    self.ButtonOverlay:SetParent(button)
    self.ButtonOverlay:SetPoint("TOPLEFT", -1, 1)
    self.ButtonOverlay:SetPoint("BOTTOMRIGHT", 1, -1)  
    
    local back = button:CreateTexture(nil, "BACKGROUND")
    back:SetPoint("TOPLEFT",button.icon,"TOPLEFT",-4,4)
    back:SetPoint("BOTTOMRIGHT",button.icon,"BOTTOMRIGHT",4,-4)
    back:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\simplesquare_glow")
    back:SetVertexColor(0, 0, 0, 1)
    
  end
  
  --buff func
  local function d3o2_createBuffs(self,unit)
  --changed buff & debuff locations to top of target frame, and bottom of respectively
    self.Buffs = CreateFrame("Frame", nil, self)
    self.Buffs.size = 22
    self.Buffs.num = 40
    self.Buffs:SetHeight((self.Buffs.size+5)*3)
    self.Buffs:SetWidth(self.width)
    self.Buffs:SetPoint("BOTTOM", self, "TOP", 0, 0)
    self.Buffs.initialAnchor = "TOPLEFT"
    self.Buffs["growth-x"] = "RIGHT"
    self.Buffs["growth-y"] = "UP"
    self.Buffs.spacing = 5
  end
  
  --debuff func
  local function d3o2_createDebuffs(self,unit)
    self.Debuffs = CreateFrame("Frame", nil, self)
    if unit == "target" then
      self.Debuffs.size = 22
      self.Debuffs.num = 40
      self.Debuffs:SetHeight((self.Debuffs.size+5)*3)
      self.Debuffs:SetWidth(self.width)
      self.Debuffs:SetPoint("TOP", self, "BOTTOM", 0, -15)
      self.Debuffs.initialAnchor = "TOPLEFT"
      self.Debuffs["growth-x"] = "RIGHT"
      self.Debuffs["growth-y"] = "DOWN"
      self.Debuffs.spacing = 5
    elseif unit == "targettarget" then
      self.Debuffs.size = 20
      self.Debuffs.num = 8
      self.Debuffs:SetHeight((self.Debuffs.size+5)*1)
      self.Debuffs:SetWidth(self.width)
      self.Debuffs:SetPoint("TOP", self, "BOTTOM", 0, -15)
      self.Debuffs.initialAnchor = "TOPLEFT"
      self.Debuffs["growth-x"] = "RIGHT"
      self.Debuffs["growth-y"] = "DOWN"
      self.Debuffs.spacing = 5      
    else
      self.Debuffs.size = 34
      self.Debuffs.num = 3
      self.Debuffs:SetHeight((self.Debuffs.size+5)*1)
      self.Debuffs:SetWidth(self.width)
      self.Debuffs:SetPoint("TOP", self, "BOTTOM", 0, -17)
      self.Debuffs.initialAnchor = "TOPLEFT"
      self.Debuffs["growth-x"] = "RIGHT"
      self.Debuffs["growth-y"] = "DOWN"
      self.Debuffs.spacing = 5      
    end
    self.Debuffs.onlyShowPlayer = false
    self.Debuffs.showDebuffType = false
  end
  
  local function d3o2_createCastbar(self,unit)
    self.Castbar = CreateFrame("StatusBar", nil, UIParent)
    self.Castbar:SetFrameStrata("MEDIUM")
    self.Castbar:SetWidth(224)
    self.Castbar:SetHeight(18)
    self.Castbar:SetStatusBarTexture(statusbar256)
    self.Castbar.bg2 = self.Castbar:CreateTexture(nil, "BACKGROUND")
    self.Castbar.bg2:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_targetframe.tga")
    self.Castbar.bg2:SetWidth(512)
    self.Castbar.bg2:SetHeight(128)
    self.Castbar.bg2:SetPoint("CENTER",-3,0)
    self.Castbar.bg = self.Castbar:CreateTexture(nil, "BORDER")
    self.Castbar.bg:SetTexture(statusbar256)
    self.Castbar.bg:SetAllPoints(self.Castbar)
    if color_switcher == 1 then
      self.Castbar.bg:SetVertexColor(0.15,0.15,0.15,1)
      self.Castbar:SetStatusBarColor(180/255,110/255,30/255,1)
    else
      self.Castbar.bg:SetVertexColor(180/255,110/255,30/255,1)
      self.Castbar:SetStatusBarColor(0.15,0.15,0.15,1)
    end
    --commented this function out to prevent the castbar from loading
    --if unit == "player" then
      --self.Castbar:SetPoint(tabvalues.frame_positions[13].a1, tabvalues.frame_positions[13].af, tabvalues.frame_positions[13].a2, tabvalues.frame_positions[13].x, tabvalues.frame_positions[13].y)
    --elseif unit == "target" then
      --self.Castbar:SetPoint(tabvalues.frame_positions[12].a1, tabvalues.frame_positions[12].af, tabvalues.frame_positions[12].a2, tabvalues.frame_positions[12].x, tabvalues.frame_positions[12].y)
    --elseif unit == "focus" then
      --self.Castbar:SetPoint(tabvalues.frame_positions[14].a1, tabvalues.frame_positions[14].af, tabvalues.frame_positions[14].a2, tabvalues.frame_positions[14].x, tabvalues.frame_positions[14].y)
    --end
    
    self.Castbar.Text = SetFontString(self.Castbar, d3font, 14, "THINOUTLINE")
    self.Castbar.Text:SetPoint("LEFT", 2, 1)
    self.Castbar.Text:SetPoint("RIGHT", -50, 1)
    self.Castbar.Text:SetJustifyH("LEFT")
    
    self.Castbar.Time = SetFontString(self.Castbar, d3font, 14, "THINOUTLINE")
    self.Castbar.Time:SetPoint("RIGHT", -2, 1)
    
    --safezone
    if use_castbar_latency_zone == 1 then
      if unit == "player" then
        self.Castbar.SafeZone = self.Castbar:CreateTexture(nil,"LOW")
        self.Castbar.SafeZone:SetTexture(statusbar256)
        self.Castbar.SafeZone:SetVertexColor(0.6,0,0,1)
        self.Castbar.SafeZone:SetPoint("TOPRIGHT")
        self.Castbar.SafeZone:SetPoint("BOTTOMRIGHT")
      end
    end
    
    --icon
    self.Castbar.Icon = self.Castbar:CreateTexture(nil, "BORDER")
    self.Castbar.Icon:SetWidth(32)
    self.Castbar.Icon:SetHeight(32)
    self.Castbar.Icon:SetPoint("LEFT", -77, 0)
    self.Castbar.Icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
    
    self.Castbar.IconBack = self.Castbar:CreateTexture(nil, "BACKGROUND")
    self.Castbar.IconBack:SetPoint("TOPLEFT",self.Castbar.Icon,"TOPLEFT",-5,5)
    self.Castbar.IconBack:SetPoint("BOTTOMRIGHT",self.Castbar.Icon,"BOTTOMRIGHT",5,-5)
    self.Castbar.IconBack:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\simplesquare_glow")
    self.Castbar.IconBack:SetVertexColor(0, 0, 0, 1)
    
    self.Castbar.IconOverlay = self.Castbar:CreateTexture(nil, "OVERLAY")
    self.Castbar.IconOverlay:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\gloss2.tga")
    self.Castbar.IconOverlay:SetVertexColor(0.37,0.3,0.3,1);
    self.Castbar.IconOverlay:SetPoint("TOPLEFT", self.Castbar.Icon, "TOPLEFT", -1, 1)
    self.Castbar.IconOverlay:SetPoint("BOTTOMRIGHT", self.Castbar.Icon, "BOTTOMRIGHT", 1, -1)  
    
    
    self.Castbar:SetScale(targetscale)
  
  end
  
  --lowhp func
  local function d3o2_createLowHP(self,unit)
    if unit == "player" then
      self.LowHP = self.Health:CreateTexture(nil, "ARTWORK")
      self.LowHP:SetAllPoints(self.Health)
      self.LowHP:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_lowhp_glow.tga")
      self.LowHP:SetBlendMode("BLEND")
      self.LowHP:SetVertexColor(1, 0, 0, 1)
      self.LowHP:Hide()
    elseif unit == "target" then
      self.LowHP = self.Health:CreateTexture(nil, "ARTWORK")
      self.LowHP:SetWidth(505)
      self.LowHP:SetHeight(115)
      self.LowHP:SetPoint("CENTER",-3,0)
      self.LowHP:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_targetframe_lowhp.tga")
      self.LowHP:SetBlendMode("ADD")
      self.LowHP:SetVertexColor(1, 0, 0, 1)
      self.LowHP:SetAlpha(0.8)
      self.LowHP:Hide()    
    else
      self.LowHP = self.Health:CreateTexture(nil, "ARTWORK")
      self.LowHP:SetWidth(250)
      self.LowHP:SetHeight(115)
      self.LowHP:SetPoint("CENTER",-2,0)
      self.LowHP:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3totframe_lowhp.tga")
      self.LowHP:SetBlendMode("ADD")
      self.LowHP:SetVertexColor(1, 0, 0, 1)
      self.LowHP:SetAlpha(0.8)
      self.LowHP:Hide()
    end
  end
  
  local function d3o2_createDebuffGlow(self,unit)
    if unit == "player" then
      self.DebuffHighlight = self:CreateTexture(nil, "BACKGROUND")
      --self.DebuffHighlight:SetAllPoints(self)
      self.DebuffHighlight:SetWidth(self.width)
      self.DebuffHighlight:SetHeight(self.width)
      self.DebuffHighlight:SetPoint("CENTER",0,0)
      self.DebuffHighlight:SetBlendMode("BLEND")
      self.DebuffHighlight:SetVertexColor(1, 0, 0, 0) -- set alpha to 0 to hide the texture
      self.DebuffHighlightAlpha = 0.7
      self.DebuffHighlightFilter = false
      self.DebuffHighlight:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\orb_debuff_glow.tga")
    elseif unit == "target" then
      self.DebuffHighlight = self:CreateTexture(nil, "OVERLAY")
      self.DebuffHighlight:SetWidth(302)
      self.DebuffHighlight:SetHeight(self.DebuffHighlight:GetWidth()/4)
      self.DebuffHighlight:SetPoint("CENTER",-3,0)
      self.DebuffHighlight:SetBlendMode("BLEND")
      self.DebuffHighlight:SetVertexColor(1, 0, 0, 0) -- set alpha to 0 to hide the texture
      self.DebuffHighlightAlpha = 0.8
      self.DebuffHighlightFilter = true      
      self.DebuffHighlight:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_nameplate_border_glow.tga")        
    elseif unit == "targettarget" then
      self.DebuffHighlight = self:CreateTexture(nil, "OVERLAY")
      self.DebuffHighlight:SetWidth(256)
      self.DebuffHighlight:SetHeight(self.DebuffHighlight:GetWidth()/2)
      self.DebuffHighlight:SetPoint("CENTER",-2,0)
      self.DebuffHighlight:SetBlendMode("BLEND")
      self.DebuffHighlight:SetVertexColor(1, 0, 0, 0) -- set alpha to 0 to hide the texture
      self.DebuffHighlightAlpha = 0.8
      self.DebuffHighlightFilter = true
      self.DebuffHighlight:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3totframe_debuff.tga")
    else
      self.DebuffHighlight = self:CreateTexture(nil, "OVERLAY")
      self.DebuffHighlight:SetWidth(256)
      self.DebuffHighlight:SetHeight(115)
      self.DebuffHighlight:SetPoint("BOTTOM",-2,-50)
      self.DebuffHighlight:SetBlendMode("BLEND")
      self.DebuffHighlight:SetVertexColor(1, 0, 0, 0) -- set alpha to 0 to hide the texture
      self.DebuffHighlightAlpha = 0.8
      self.DebuffHighlightFilter = true
      self.DebuffHighlight:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3totframe_debuff.tga")
    end
  end
  
  --create the elite head texture
  local bubblehead
  local function d3o2_createBubbleHead(self,unit)
    local headsize = 100
    local head = self.Health:CreateTexture(nil,"OVERLAY")
    head:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_head_trans")
    head:SetWidth(headsize)
    head:SetHeight(headsize/2)
    head:SetPoint("TOP",0,-6)
    bubblehead = head
    bubblehead:Hide()
  end
  
  -- check threat
  local function check_threat(self,event,unit)
    if unit then
      if self.unit ~= unit then
        return
      end
      local threat = UnitThreatSituation(unit)
  		if threat == 3 then
  		  self.Portrait_glosst:SetVertexColor(1,0,0)
  		elseif threat == 2 then
  		  self.Portrait_glosst:SetVertexColor(1,0.6,0)
  		else
  		  self.Portrait_glosst:SetVertexColor(0.37,0.3,0.3)
  		end
	  end
  end
  
  --create portraits func
  local function d3o2_createPortraits(self,unit)
    self.Portrait_bgf = CreateFrame("Frame",nil,self)
    self.Portrait_bgf:SetPoint("BOTTOM",self.Health,"TOP",0,14)
    self.Portrait_bgf:SetWidth(self.width+10)
    self.Portrait_bgf:SetHeight(self.width+10)  
    
    local back = self.Portrait_bgf:CreateTexture(nil, "BACKGROUND")
    back:SetPoint("TOPLEFT",self.Portrait_bgf,"TOPLEFT",-15,15)
    back:SetPoint("BOTTOMRIGHT",self.Portrait_bgf,"BOTTOMRIGHT",15,-15)
    back:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\simplesquare_glow")
    back:SetVertexColor(0, 0, 0, 0.7)
    
    self.Portrait_bgt = self.Portrait_bgf:CreateTexture(nil, "BACKGROUND")
    self.Portrait_bgt:SetAllPoints(self.Portrait_bgf)
    self.Portrait_bgt:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3portrait_back2.tga")
    self.Portrait_bgt:SetVertexColor(0.7,0.7,0.7)
  
    if use_3dportraits == 1 and unit ~= "focustarget" then
      self.Portrait = CreateFrame("PlayerModel", nil, self.Portrait_bgf)
      self.Portrait:SetPoint("TOPLEFT",self.Portrait_bgf,"TOPLEFT",4,-4)
      self.Portrait:SetPoint("BOTTOMRIGHT",self.Portrait_bgf,"BOTTOMRIGHT",-4,4)

      self.Portrait_glossf = CreateFrame("Frame",nil,self.Portrait)
      self.Portrait_glossf:SetAllPoints(self.Portrait_bgf)
    else
      self.Portrait = self.Portrait_bgf:CreateTexture(nil, "BORDER")
      self.Portrait:SetPoint("TOPLEFT",self.Portrait_bgf,"TOPLEFT",2,-2)
      self.Portrait:SetPoint("BOTTOMRIGHT",self.Portrait_bgf,"BOTTOMRIGHT",-2,2)

      self.Portrait_glossf = CreateFrame("Frame",nil,self.Portrait_bgf)
      self.Portrait_glossf:SetAllPoints(self.Portrait_bgf)
    end

    self.Portrait_glosst = self.Portrait_glossf:CreateTexture(nil, "ARTWORK")
    self.Portrait_glosst:SetAllPoints(self.Portrait_glossf)
    self.Portrait_glosst:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\simplesquare_roth")
    self.Portrait_glosst:SetVertexColor(0.37,0.3,0.3)

    self.Name:SetPoint("BOTTOM", self.Portrait_bgf, "TOP", 0, 5)
    self.Name:SetFont(d3font,22,"THINOUTLINE")
  end
  
  local function d3o2_createAuraWatch(self,unit)
    --if unit ~= "target" then return end
    -- We only want to create this for the target
    local auras = CreateFrame("Frame", nil, self)
    auras:SetWidth(34)
    auras:SetHeight(34)
    auras:SetPoint("BOTTOMLEFT", self.Health, "TOPRIGHT", 58, -25)
    
    local spellIDs = { 
      48440, --reju
      48443, --regrowth
      48450, --lifebloom
      53249, --wildgrowth
    }
    
    auras.presentAlpha = 1
    auras.missingAlpha = 0
    auras.PostCreateIcon = d3o2_createAuraIcon
    auras.icons = {}
    for i, sid in pairs(spellIDs) do
      local icon = CreateFrame("Frame", nil, auras)
      icon.spellID = sid
      icon:SetWidth(34)
      icon:SetHeight(34)
      icon:SetPoint("RIGHT", auras, "LEFT", 0, 38*i)
      auras.icons[sid] = icon
    end
    self.AuraWatch = auras
  end
  
  --create special icons (raid, leader)
  local function d3o2_createIcons(self,unit)
    if unit == "player" then
      --nothing   
    elseif unit == "target" then
      self.RaidIcon = self:CreateTexture(nil, "OVERLAY")
      self.RaidIcon:SetHeight(24)
      self.RaidIcon:SetWidth(24)
      self.RaidIcon:SetPoint("RIGHT", self.Name, "LEFT", -5, 2)
      self.RaidIcon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
    else
      self.RaidIcon = self:CreateTexture(nil, "OVERLAY")
      self.RaidIcon:SetHeight(16)
      self.RaidIcon:SetWidth(16)
      self.RaidIcon:SetPoint("RIGHT", self.Name, "LEFT", -2, 2)
      self.RaidIcon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
    end

    if unit == "player" then
      self.Leader = self:CreateTexture(nil, "OVERLAY")
      self.Leader:SetHeight(16)
      self.Leader:SetWidth(16)
      self.Leader:SetPoint("TOPLEFT", self, "TOPLEFT", 0, 0)
      self.Leader:SetTexture("Interface\\GroupFrame\\UI-Group-LeaderIcon")    
    elseif unit == "target" or unit == "targettarget" then 
      -- nothing
    else
      self.Leader = self:CreateTexture(nil, "OVERLAY")
      self.Leader:SetHeight(24)
      self.Leader:SetWidth(24)
      self.Leader:SetPoint("RIGHT", self.Health, "LEFT", -22, 22)
      self.Leader:SetTexture("Interface\\GroupFrame\\UI-Group-LeaderIcon")      
    end
    
	  self.PvP = self:CreateTexture(nil, "OVERLAY")
      self.PvP:SetHeight(30)
      self.PvP:SetWidth(30)
      self.PvP:SetPoint("TOPRIGHT", self, "TOPRIGHT", 0, 0)
  end  

  --thanks to p3lim for this one
  --it does fix the vehicle combopoints
  local function updateCombo(self, event, unit)
    if(unit == PlayerFrame.unit and unit ~= self.CPoints.unit) then
      self.CPoints.unit = unit
    end
  end

  local function d3o2_createComboPoints(self,unit)
    self.CPoints = SetFontString(self.Health, d3font, 24, "THINOUTLINE")
    self.CPoints:SetPoint("LEFT", self.Name, "RIGHT", 2, -1)
    self.CPoints:SetTextColor(1, .5, 0)
    self.CPoints.unit = "player"
    self:RegisterEvent("UNIT_COMBO_POINTS", updateCombo)
  end
  
  local function make_me_movable(f)
    if allow_frame_movement == 0 then
      f:IsUserPlaced(false)
    else
      f:SetMovable(true)
      f:SetUserPlaced(true)
      if lock_all_frames == 0 then
        f:EnableMouse(true)
        f:RegisterForDrag("LeftButton","RightButton")
        f:SetScript("OnDragStart", function(self) self:StartMoving() end)
        f:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
      end
    end  
  end
  
  -----------------------------
  -- CUSTOM TAGS
  -----------------------------
  
  oUF.Tags["[d3o2misshp]"] = function(unit) 
    local max, min = UnitHealthMax(unit), UnitHealth(unit)
    local v = max-min
    local string = ""
    if UnitIsDeadOrGhost(unit) == 1 then
      string = "dead"
	elseif UnitIsAFK(unit) == 1 then
	  string = "AFK"
    elseif UnitIsConnected(unit) == nil then
      string = "off"
    elseif v == 0 then
      string = ""
    elseif v > 1000000 then
      string = -(floor((v/1000000)*10)/10).."m"
    elseif v > 1000 then
      string = -(floor((v/1000)*10)/10).."k"
    else
      string = -v
    end  
    return string
  end
  oUF.TagEvents["[d3o2misshp]"] = "UNIT_HEALTH"
  
  oUF.Tags["[d3o2abshp]"] = function(unit) 
    local v = UnitHealth(unit)
    local string = ""
    if UnitIsDeadOrGhost(unit) == 1 then
      string = "dead"
    elseif UnitIsConnected(unit) == nil then
      string = "off"
    else
      string = do_format(v)
    end  
    return string
  end
  oUF.TagEvents["[d3o2abshp]"] = "UNIT_HEALTH"
  
  oUF.Tags["[d3o2maxhp]"] = function(unit) 
    local v = UnitHealthMax(unit)
    local string = ""
    if v then
      string = do_format(v)
    end  
    return string
  end
  oUF.TagEvents["[d3o2maxhp]"] = "UNIT_HEALTH"
  
  oUF.Tags["[d3o2absmp]"] = function(unit) 
    local string = ""
    --if UnitPowerType(unit) == 0 then
      local v = UnitMana(unit)
      string = do_format(v)
    --end
    return string
  end
  oUF.TagEvents["[d3o2absmp]"] = "UNIT_ENERGY UNIT_FOCUS UNIT_MANA UNIT_RAGE UNIT_RUNIC_POWER"
  
  oUF.Tags["[d3o2maxmp]"] = function(unit) 
    local string = ""
    --if UnitPowerType(unit) == 0 then
      local v = UnitMana(unit)
      string = do_format(v)
    --end
    return string
  end
  oUF.TagEvents["[d3o2maxmp]"] = "UNIT_ENERGY UNIT_FOCUS UNIT_MANA UNIT_RAGE UNIT_RUNIC_POWER"
  
  oUF.Tags["[d3o2classtext]"] = function(unit) 
    bubblehead:Hide()
    local string, tmpstring, sp = "", "", " "
    if UnitLevel(unit) ~= -1 then
      string = UnitLevel(unit)
    else
      string = "??"
    end    
    string = string..sp
    local unitrace = UnitRace(unit)
    local creatureType = UnitCreatureType(unit)    
    if unitrace and UnitIsPlayer(unit) then
      string = string..unitrace..sp
    end   
    if creatureType and not UnitIsPlayer(unit) then
      string = string..creatureType..sp
    end    
    local unit_classification = UnitClassification(unit)    
    if unit_classification == "worldboss" then
      tmpstring = "Boss"
      bubblehead:Show()
      bubblehead:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_head_skull")
    elseif unit_classification == "rare" or unit_classification == "rareelite" then
      tmpstring = "Rare"
      bubblehead:Show()
      bubblehead:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_head_diablo")
      if unit_classification == "rareelite" then
        tmpstring = tmpstring.." Elite"
      end
    elseif unit_classification == "elite" then
      tmpstring = "Elite"
      bubblehead:Show()
      bubblehead:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_head_garg")
    end    
    if tmpstring ~= "" then
      tmpstring = tmpstring..sp  
    end    
    string = string..tmpstring
    tmpstring = ""    
    local localizedClass, englishClass = UnitClass(unit)
    
    if localizedClass and UnitIsPlayer(unit) then
      string = string..localizedClass..sp
    end
    return string
  end
    
  -----------------------------
  -- CREATE STYLES
  -----------------------------
    
  --create the player style
  local function CreatePlayerStyle(self, unit)
    if use_rbottombarstyler ~= 1 then
      self.width = orbsize
      d3o2_setupFrame(self,orbsize,orbsize,"BACKGROUND")  
	  d3o2_createManaOrb(self,"power") 
	  make_me_movable(self.Power)
	  d3o2_createHealthOrb(self,"health")
	  self:RegisterEvent("ADDON_LOADED")
	  self:SetScript("OnEvent", function(_,event)
		if event == "ADDON_LOADED" then
			 self:SetScale(playerscale)
		end
	  end)
	  self.Health:RegisterEvent("CHAT_MSG_ADDON")
	  self.Health:RegisterEvent("PLAYER_REGEN_DISABLED")
	  self.Health:RegisterEvent("PLAYER_REGEN_ENABLED")
	  self.Health:SetScript("OnEvent", function(_,event,arg1,arg2)
		if event == "PLAYER_REGEN_DISABLED" or event == "PLAYER_REGEN_ENABLED" then
			check_druid_mana(self, event)
		else
			check_druid_mana(self, event)
		end
		if event == "CHAT_MSG_ADDON" then
			if arg2 == "Scale Changed" then
				set_scaling(self, playerscale)
			elseif arg2 == "Frames locked" or arg2 == "Frames Movable" then
				make_health_movable(self)
			end
			if orbPos_altered == nil then
				self:ClearAllPoints()
				self:SetPoint("BOTTOM", nil, "BOTTOM", -260, -9) 
			end
		end
	  end)
	  make_me_movable(self)
      self.HealthValueHolder = CreateFrame("FRAME", nil, self.Health)
      self.HealthValueHolder:SetFrameStrata("LOW")
      self.HealthValueHolder:SetAllPoints(self.Health)
      local hpval1 = SetFontString(self.HealthValueHolder, d3font, 28, "THINOUTLINE")
      hpval1:SetPoint("CENTER", 0, 10)
      local hpval2 = SetFontString(self.HealthValueHolder, d3font, 16, "THINOUTLINE")
      hpval2:SetPoint("CENTER", 0, -10)
      hpval2:SetTextColor(0.6,0.6,0.6)
      self.PowerValueHolder = CreateFrame("FRAME", nil, self.Power)
      self.PowerValueHolder:SetFrameStrata("LOW")
      self.PowerValueHolder:SetAllPoints(self.Power)
      local mpval1 = SetFontString(self.PowerValueHolder, d3font, 28, "THINOUTLINE")
      mpval1:SetPoint("CENTER", 0, 10)
      local mpval2 = SetFontString(self.PowerValueHolder, d3font, 16, "THINOUTLINE")
      mpval2:SetPoint("CENTER", 0, -10)
      mpval2:SetTextColor(0.6,0.6,0.6)
      self:Tag(hpval1, "[perhp]")
      self:Tag(hpval2, "[d3o2abshp]")
      --cannot use custom events with frequentupdates enabled
      --self:Tag(mpval1, "[perpp]")
      --self:Tag(mpval2, "[d3o2absmp]")
      --set the subobjects to be available for the d3o2_updatePlayerPower func
      self.mpval1 = mpval1
      self.mpval2 = mpval2
      self.PostUpdateHealth = d3o2_updatePlayerHealth
      self.PostUpdatePower = d3o2_updatePlayerPower
      d3o2_createLowHP(self,unit)
      d3o2_createDebuffGlow(self,unit)
      d3o2_createIcons(self,unit)
    end
    --d3o2_createCastbar(self,unit)
    self:SetAttribute("initial-scale", playerscale)
  end
  
  --create the target style
  local function CreateTargetStyle(self, unit)
    self.width = 224
    d3o2_setupFrame(self,224,20,"BACKGROUND")
    make_me_movable(self)
    d3o2_createHealthPowerFrames(self,unit)
    d3o2_createBuffs(self,unit)
    d3o2_createDebuffs(self,unit)
    d3o2_createBubbleHead(self,unit)
    local name = SetFontString(self, d3font, 20, "THINOUTLINE")
    name:SetPoint("BOTTOM", self, "TOP", 0, 30)
    name:SetPoint("LEFT", 5,0)
    name:SetPoint("RIGHT", -5,0)
    local hpval = SetFontString(self.Health, d3font, 14, "THINOUTLINE")
    hpval:SetPoint("RIGHT", self.Health, "RIGHT", -2, 2)
    local classtext = SetFontString(self, d3font, 16, "THINOUTLINE")
    classtext:SetPoint("BOTTOM", self, "TOP", 0, 13)
    self.Name = name
    self:Tag(name, "[name]")
    self:Tag(hpval, targetframe_health_tag)
    if targetframe_power_tag then
      local ppval = SetFontString(self.Health, d3font, 14, "THINOUTLINE")
      ppval:SetPoint("LEFT", self.Health, "LEFT", 2, 2)
      self:Tag(ppval, targetframe_power_tag)    
    end
    self:Tag(classtext, "[d3o2classtext]")
    
    d3o2_createCastbar(self,unit)
    d3o2_createLowHP(self,unit)
    d3o2_createDebuffGlow(self,unit)
    d3o2_createIcons(self,unit)
    d3o2_createComboPoints(self,unit)
    
    self.PostUpdateHealth = d3o2_updateHealth
    self.PostUpdatePower = d3o2_updatePower
    self.PostCreateAuraIcon = d3o2_createAuraIcon
    self:SetAttribute("initial-scale", targetscale)
  end
  
  --create the tot style
  local function CreateToTStyle(self, unit)
    self.width = 110
    d3o2_setupFrame(self,110,20,"BACKGROUND")
    make_me_movable(self)
    d3o2_createHealthPowerFrames(self,unit)
    d3o2_createDebuffs(self,unit)
    local name = SetFontString(self, d3font, 18, "THINOUTLINE")
    name:SetPoint("BOTTOM", self, "TOP", 0, 15)
    name:SetPoint("LEFT", -3,0)
    name:SetPoint("RIGHT", 3,0)
    local hpval = SetFontString(self.Health, d3font, 14, "THINOUTLINE")
    hpval:SetPoint("RIGHT", self.Health, "RIGHT", -2, 2)
    self.Name = name
    self:Tag(name, "[name]")
    self:Tag(hpval, "[perhp]%")
    
    d3o2_createLowHP(self,unit)
    d3o2_createDebuffGlow(self,unit)
    d3o2_createIcons(self,unit)
    
    self.PostUpdateHealth = d3o2_updateHealth
    self.PostUpdatePower = d3o2_updatePower
    self.PostCreateAuraIcon = d3o2_createAuraIcon
    self:SetAttribute("initial-scale", targetscale)
  end
  
  --create the focus, pet and party style
  local function CreateFocusStyle(self, unit)
    self.width = 110
    d3o2_setupFrame(self,110,200,nil)
    d3o2_createHealthPowerFrames(self,unit)
    d3o2_createDebuffs(self,unit)
    local name = SetFontString(self, d3font, 18, "THINOUTLINE")
    name:SetPoint("BOTTOM", self, "TOP", 0, 15)
    name:SetPoint("LEFT", -3,0)
    name:SetPoint("RIGHT", 3,0)
    self.Name = name
    self:Tag(name, "[name]")
    local hpval = SetFontString(self.Health, d3font, 20, "THINOUTLINE")
    hpval:SetPoint("RIGHT", self.Health, "RIGHT", -2, 0)
    self:Tag(hpval, "[d3o2misshp]")
    
    d3o2_createLowHP(self,unit)
    d3o2_createDebuffGlow(self,unit)
    d3o2_createPortraits(self,unit)    
    if unit == "focus" then
      d3o2_createCastbar(self,unit)
    end    
    d3o2_createIcons(self,unit)
    
    if myclass == "DRUID" then
      d3o2_createAuraWatch(self,unit)
    end
    
    self:RegisterEvent("UNIT_THREAT_SITUATION_UPDATE", check_threat)
    
    self.PostUpdateHealth = d3o2_updateHealth
    self.PostUpdatePower = d3o2_updatePower
    self.PostCreateAuraIcon = d3o2_createAuraIcon
    self:SetAttribute("initial-scale", focusscale)
    
    if (not unit) then
      self.Range = true
      self.outsideRangeAlpha = 0.6
      self.inRangeAlpha = 1
    else
      make_me_movable(self)
    end
    
  end
  

  -----------------------------
  -- REGISTER STYLES, Hide/Show PlayerFrame
  -----------------------------
  local function playerFrame_load()
	PlayerFrame:RegisterEvent("ADDON_LOADED")
	PlayerFrame:RegisterEvent("CHAT_MSG_ADDON")
	PlayerFrame:SetScript("OnEvent", function(_, event)
		if event == "ADDON_LOADED" then
			if load_playerFrame == nil or load_playerFrame == 0 then
				PlayerFrame:SetScript("OnEvent", nil);
				PlayerFrame:Hide();
			elseif load_playerFrame == 1 then
				PlayerFrame:SetScript("OnEvent", PlayerFrame_OnEvent);
				PlayerFrame:Show();
			end
		elseif event == "CHAT_MSG_ADDON" then
			if showPFrame == true and not PlayerFrame:IsVisible() then
				PlayerFrame:SetScript("OnEvent", PlayerFrame_OnEvent);
				PlayerFrame:Show();
			elseif showPFrame == false and PlayerFrame:IsVisible() then
				PlayerFrame:SetScript("OnEvent", nil)
				PlayerFrame:Hide();
			end
		end
	end)
  end
  playerFrame_load()


  oUF:RegisterStyle("oUF_D3Orbs2_player", CreatePlayerStyle)
  --oUF:RegisterStyle("oUF_D3Orbs2_target", CreateTargetStyle)
  --oUF:RegisterStyle("oUF_D3Orbs2_tot", CreateToTStyle)
  --oUF:RegisterStyle("oUF_D3Orbs2_focus", CreateFocusStyle)
  
  -----------------------------
  -- SPAWN UNITS
  -----------------------------
  
  --oUF:SetActiveStyle("oUF_D3Orbs2_target")
  oUF:SetActiveStyle("oUF_D3Orbs2_player")
  oUF:Spawn("player", "oUF_D3Orbs2_PlayerFrame"):SetPoint(tabvalues.frame_positions[2].a1, tabvalues.frame_positions[2].af, tabvalues.frame_positions[2].a2, tabvalues.frame_positions[2].x, tabvalues.frame_positions[2].y) 
  
  ------------------------
  -- Spawn replacement test
  ------------------------
	--local player = "player"
  	--makeOrbFrames = CreateFrame("Button", "oUF_D3Orbs2_PlayerFrame", UIParent, "SecureUnitButtonTemplate")
	--makeOrbFrames:SetAttribute("unit", player)
	--makeOrbFrames.player = player
	--makeOrbFrames.id = player:match"^.-(%d+)"
	--units[player] = makeOrbFrames
	--walkObject(makeOrbFrames, player)
	--HandleUnit(player, makeOrbFrames)
	--RegisterUnitWatch(makeOrbFrames)
	--makeOrbFrames:SetPoint(tabvalues.frame_positions[2].a1, tabvalues.frame_positions[2].af, tabvalues.frame_positions[2].a2, tabvalues.frame_positions[2].x, tabvalues.frame_positions[2].y) 
  
  --oUF:SpawnHeader("oUF_D3Orbs2_PlayerFrame", nil, true):SetPoint(tabvalues.frame_positions[2].a1, tabvalues.frame_positions[2].af, tabvalues.frame_positions[2].a2, tabvalues.frame_positions[2].x, tabvalues.frame_positions[2].y)
  --oUF:Spawn("target","oUF_D3Orbs2_TargetFrame"):SetPoint(tabvalues.frame_positions[3].a1, tabvalues.frame_positions[3].af, tabvalues.frame_positions[3].a2, tabvalues.frame_positions[3].x, tabvalues.frame_positions[3].y)  
  --oUF:SetActiveStyle("oUF_D3Orbs2_tot")
  --oUF:Spawn("targettarget","oUF_D3Orbs2_ToT"):SetPoint(tabvalues.frame_positions[4].a1, tabvalues.frame_positions[4].af, tabvalues.frame_positions[4].a2, tabvalues.frame_positions[4].x, tabvalues.frame_positions[4].y)
  --oUF:SetActiveStyle("oUF_D3Orbs2_focus")
  --oUF:Spawn("focus","oUF_D3Orbs2_focus"):SetPoint(tabvalues.frame_positions[6].a1, tabvalues.frame_positions[6].af, tabvalues.frame_positions[6].a2, tabvalues.frame_positions[6].x, tabvalues.frame_positions[6].y)
  --oUF:Spawn("focustarget","ouf_focustot"):SetPoint("CENTER", oUF.units.focus, "CENTER", 200, 0)
  --oUF:Spawn("pet","ouf_pet"):SetPoint("CENTER", oUF.units.focus, "CENTER", 0, 250)
  
 -- local oUF_D3Orbs_PartyDragFrame = CreateFrame("Frame","oUF_D3Orbs_PartyDragFrame",UIParent)
  --oUF_D3Orbs_PartyDragFrame:SetWidth(80)
  --oUF_D3Orbs_PartyDragFrame:SetHeight(100)
  --if lock_all_frames == 0 then
    --oUF_D3Orbs_PartyDragFrame:SetBackdrop({bgFile = "Interface/Tooltips/UI-Tooltip-Background", edgeFile = "", tile = true, tileSize = 16, edgeSize = 16, insets = { left = 0, right = 0, top = 0, bottom = 0 }})
  --end
  --oUF_D3Orbs_PartyDragFrame:SetPoint(tabvalues.frame_positions[7].a1, tabvalues.frame_positions[7].af, tabvalues.frame_positions[7].a2, tabvalues.frame_positions[7].x, tabvalues.frame_positions[7].y)
  --make_me_movable(oUF_D3Orbs_PartyDragFrame)
  
  --local party  = oUF:Spawn("header", "oUF_Party")
  --party:SetPoint("TOPLEFT",oUF_D3Orbs_PartyDragFrame,"TOPLEFT",13,60)
  --party:SetManyAttributes("showParty", true, "xOffset", 80, "point", "LEFT", "showPlayer", true)
  --party:SetAttribute("showRaid", false)
  --party:Show()
  
  -----------------------------
  -- CREATING D3 ART FRAMES
  -----------------------------

 local function createArt()
    local d3f = CreateFrame("Frame","oUF_D3Orbs_AngelFrame",UIParent)
    d3f:SetFrameStrata("FULLSCREEN_DIALOG")
    d3f:SetWidth(160)
    d3f:SetHeight(160)
	make_me_movable(d3f)
	d3f:SetPoint(tabvalues.frame_positions[8].a1, tabvalues.frame_positions[8].af, tabvalues.frame_positions[8].a2, tabvalues.frame_positions[8].x, tabvalues.frame_positions[8].y)
    d3f:Show()
	d3f:RegisterEvent("ADDON_LOADED")
    d3f:RegisterEvent("CHAT_MSG_ADDON")
	d3f:SetScript("OnEvent", function(_, event,arg1,arg2)
	  if event == "CHAT_MSG_ADDON" then
		if arg2 == "Scale Changed" then
			set_scaling(d3f, playerscale)
		else
			make_d3f_movable(d3f)
		end
	  end
		if event == "CHAT_MSG_ADDON" and orbPos_altered == nil then
			d3f:ClearAllPoints()
			d3f:SetPoint("BOTTOM", nil, "BOTTOM", 333, 0)
		end
		if event == "CHAT_MSG_ADDON" then
			if update_liveAngelDemon == "show" then
				d3f:Show()
			elseif update_liveAngelDemon == "hide" then
				d3f:Hide()
			end
		end
		if event == "ADDON_LOADED" then
			
			if load_demon_angel == 0 then
				d3f:Hide()
			elseif load_demon_angel == 1 or load_demon_angel == nil then
				d3f:Show()
			end
			if reloadStuff == nil then
				d3f:ClearAllPoints()
				d3f:SetPoint("BOTTOM", nil, "BOTTOM", 333, 0)
				reloadStuff = 1
			end
		end
	end)
    local d3t = d3f:CreateTexture(nil,"BACKGROUND")
    d3t:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_angel2test")
    d3t:SetAllPoints(d3f)
  
    local d3f2 = CreateFrame("Frame","oUF_D3Orbs_DemonFrame",UIParent)
    d3f2:SetFrameStrata("FULLSCREEN_DIALOG")
    d3f2:SetWidth(160)
    d3f2:SetHeight(160)
	make_me_movable(d3f2)
    d3f2:SetPoint(tabvalues.frame_positions[9].a1, tabvalues.frame_positions[9].af, tabvalues.frame_positions[9].a2, tabvalues.frame_positions[9].x, tabvalues.frame_positions[9].y)
    d3f2:Show()
	d3f2:RegisterEvent("ADDON_LOADED")
	d3f2:RegisterEvent("CHAT_MSG_ADDON")
	d3f2:SetScript("OnEvent", function(_, event,arg1,arg2)
	  if event == "CHAT_MSG_ADDON" then
		if arg2 == "Scale Changed" then
			set_scaling(d3f2, playerscale)
		else
			make_d3f2_movable(d3f2)
		end
	  end
		if event == "CHAT_MSG_ADDON" and orbPos_altered == nil then
			d3f2:ClearAllPoints()
		    d3f2:SetPoint("BOTTOM", nil, "BOTTOM", -345, 0)
		end
		if event == "CHAT_MSG_ADDON" then
			if update_liveAngelDemon == "show" then
				d3f2:Show()
			elseif update_liveAngelDemon == "hide" then
				d3f2:Hide()
			end
		end
		if event == "ADDON_LOADED" then
			if load_demon_angel == 0 then
				d3f2:Hide()
			elseif load_demon_angel == 1 or load_demon_angel == nil then
				d3f2:Show()
			end
			if reloadStuff == nil then
				d3f2:ClearAllPoints()
				d3f2:SetPoint("BOTTOM", nil, "BOTTOM", -345, 0)
				reloadStuff = 1
			end
		end
	end)
    local d3t2 = d3f2:CreateTexture(nil,"BACKGROUND")
    d3t2:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\d3_demon2test")
    d3t2:SetAllPoints(d3f2)
end
 createArt()
 
 local function checkPower()
	if myclass == "WARLOCK" then
		if UnitLevel("player") < 10 then
			return 0
		else
			return UnitPower("player", 7)
		end
	elseif myclass == "PALADIN" then
		return UnitPower("player", 9)
	end
 end
 
	local powers = CreateFrame("Frame","oUF_D3Orbs_Powers",UIParent)  -- this is going to be pretty similar to the art frames here and will be treated as such
    powers:SetFrameStrata("TOOLTIP")
    powers:SetWidth(35)
    powers:SetHeight(35)
	powers:ClearAllPoints()
    powers:SetPoint("BOTTOM", -330, 105)
    powers:Show()
	make_me_movable(powers)
	local p1 = powers:CreateTexture(nil, "ARTWORK") -- p1 is our movement indicator, it will show up when the user chooses to move the frame
	p1:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\powersMask")
	p1:Hide()
	local p2 = powers:CreateTexture(nil,"BACKGROUND")
	local p3 = powers:CreateTexture(nil, "OVERLAY")
	local p4 = powers:CreateTexture(nil, "OVERLAY")
	local p5 = powers:CreateTexture(nil, "OVERLAY")
	if myclass == "WARLOCK" then
	p2:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\lockSmallGloss")
	p3:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\lockone")
	p4:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\locktwo")
	p5:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\lockthree")
	elseif myclass == "PALADIN" then
	p2:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\smallGloss")
	p3:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\one")
	p4:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\two")
	p5:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\three")
	end
	p1:SetAllPoints(powers)
    p2:SetAllPoints(powers)
	p3:SetAllPoints(powers)
	p4:SetAllPoints(powers)
	p5:SetAllPoints(powers)
	if myclass == "WARLOCK" or myclass == "PALADIN" then
		powers:RegisterEvent("ADDON_LOADED")
		powers:RegisterEvent("CHAT_MSG_ADDON")
		powers:RegisterEvent("COMBAT_LOG_UNFILTERED")--we don't want to register these events if player is not a lock or pally we're not going to be monitoring for stuff
	else
		powers:Hide()
	end
	powers:SetScript("OnUpdate", function(_,event)
	if powers:IsVisible() then
		if checkPower() == 0 then
			p2:Hide()
			p3:Hide()
			p4:Hide()
			p5:Hide()
		elseif checkPower() == 1 then
				p2:Show()
				if not p3:IsVisible() then
					p3:Show()
				end
				if p4:IsVisible() then
					p4:Hide()
				end
				if p5:IsVisible() then
					p5:Hide()
				end
		elseif checkPower() == 2 then
				p2:Show()
				if p3:IsVisible() then
					p3:Hide()
				end
				if not p4:IsVisible() then
					p4:Show()
				end
				if p5:IsVisible() then
					p5:Hide()
				end
		elseif checkPower() == 3 then
				p2:Show()
				if p3:IsVisible() then
					p3:Hide()
				end
				if p4:IsVisible() then
					p4:Hide()
				end
				if not p5:IsVisible() then
					p5:Show()
				end
		end
	end
	end)
	powers:SetScript("OnEvent", function(_,event,arg1,arg2)
	  if event == "CHAT_MSG_ADDON"  then
		if update_powers == "show" or update_powers == nil then
			if allow_frame_movement == 0 then
				p1:Hide()
				make_powers_movable(powers)  
			elseif lock_all_frames == 1 then
				p1:Hide()
				make_powers_movable(powers)
			elseif lock_all_frames == 0 then
				p1:Show()
				make_powers_movable(powers)
			end
		end
	end
	  if event == "CHAT_MSG_ADDON" and power_moved == nil then
		powers:ClearAllPoints()
		powers:SetPoint("BOTTOM", -330, 105) --puts the powers frame back to the default position
	  end
	  if event == "CHAT_MSG_ADDON" then
		if arg2 == "Scale Changed" then
			set_scaling(powers, playerscale)
		elseif update_powers == "show" then
			powers:Show()
			powers:RegisterEvent("COMBAT_LOG_UNFILTERED")
		elseif update_powers == "hide" then
			powers:Hide()
			powers:UnregisterEvent("COMBAT_LOG_UNFILTERED") -- we don't want to monitor the combat log if this is not being shown
		end
	  end
	if event == "ADDON_LOADED" then
		powers:SetScale(playerscale)
		if load_power == 0 then
			powers:Hide()
			powers:UnregisterEvent("COMBAT_LOG_UNFILTERED")
		elseif load_power == 1 or load_powers == nil then
			powers:Show()
			powers:RegisterEvent("COMBAT_LOG_UNFILTERED")
		end
	end
   end)
  
 --local d3f3 = CreateFrame("Frame","oUF_D3Orbs_BottomBarLine",UIParent)
    --d3f3:SetFrameStrata("TOOLTIP")
    --d3f3:SetWidth(500)
    --d3f3:SetHeight(112)
    --d3f3:SetPoint(tabvalues.frame_positions[10].a1, tabvalues.frame_positions[10].af, tabvalues.frame_positions[10].a2, tabvalues.frame_positions[10].x, tabvalues.frame_positions[10].y)
    --d3f3:Show()
    --d3f3:SetScale(playerscale)
    --make_me_movable(d3f3)
    --local d3t3 = d3f3:CreateTexture(nil,"BACKGROUND")
    --d3t3:SetTexture("Interface\\AddOns\\rTextures\\d3_bottom")
    --d3t3:SetAllPoints(d3f3)
    
    --local d3f4 = CreateFrame("Frame","oUF_D3Orbs_BottomBarArt",UIParent)
    --d3f4:SetFrameStrata("BACKGROUND")
    --d3f4:SetWidth(512)
    --d3f4:SetHeight(256)
    --d3f4:SetPoint(tabvalues.frame_positions[11].a1, tabvalues.frame_positions[11].af, tabvalues.frame_positions[11].a2, tabvalues.frame_positions[11].x, tabvalues.frame_positions[11].y)
    --d3f4:Show()
    --d3f4:SetScale(playerscale)
    --make_me_movable(d3f4)
    --local d3t4 = d3f4:CreateTexture(nil,"BACKGROUND")
    --d3t4:SetAllPoints(d3f4)
    
    --if usebar == 2 then
      --d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar1")
    --elseif usebar == 3 then
     -- d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar2")
   -- elseif usebar == 4 then
     -- d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar3")
    --else
      --if MultiBarBottomRight:IsShown() then
      --  d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar3")
      --elseif MultiBarBottomLeft:IsShown() then
       -- d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar2")
      --else
       -- d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar1")
      --end
      --MultiBarBottomRight:HookScript("OnShow", function() d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar3") end)
      --MultiBarBottomRight:HookScript("OnHide", function() d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar2") end)
      --MultiBarBottomLeft:HookScript("OnShow", function() d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar2") end)
      --MultiBarBottomLeft:HookScript("OnHide", function() d3t4:SetTexture("Interface\\AddOns\\rTextures\\bar1") end)
    --end
	
	--**************************************************************************************************************************************
														--Menu GUI Structure --
	--**************************************************************************************************************************************
	local function makeGUIMovable(self)
	  self:SetClampedToScreen(true)
	  self:SetMovable(true)
      self:EnableMouse(true)
      self:RegisterForDrag("LeftButton","RightButton")
      self:SetScript("OnDragStart", function(self) self:StartMoving() end)
      self:SetScript("OnDragStop", function(self) self:StopMovingOrSizing() end)
	end
	
	--function to facilitate interactive color changing
	local function colorSelector(name, element)
		if name == "hOrb" then
			set_health_color = element
		elseif name == "mOrb" then
			if element == 0 then
				set_mana_color = nil
			else
			set_mana_color = element
			end
		elseif name == "kMana" then
			set_kitty_mana = element
		elseif name == "bMana" then
			set_bear_mana = element
		elseif name == "cOrb" then
			if element == 0 then
				set_combat_color = 1
			else
				set_combat_color = element
			end
		end
		set_d3_colors()
		SendAddonMessage("oUF D3 Orbs", "Colors Changed", "WHISPER", UnitName("player"))
		stringcheck = "changed"
	
	end
	
	
	--GUI Frame Parent
	local GUI = CreateFrame("Frame","oUF_D3Orbs_GUI",UIParent)  
    GUI:SetFrameStrata("BACKGROUND")
    GUI:SetWidth(615)
    GUI:SetHeight(515)
	GUI:ClearAllPoints()
    GUI:SetPoint("CENTER", 0, 0)
    GUI:Hide()
	makeGUIMovable(GUI)
    GUI:SetScale(0.85)
	local g1 = GUI:CreateTexture(nil, "BACKGROUND")
	g1:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\MenuFrame")
	g1:SetAllPoints(GUI)
	
	--close button
	local cBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	cBtn:SetWidth(75)
	cBtn:SetHeight(25)
	cBtn:SetText("Close")
	cBtn:SetPoint("BOTTOM", g1, 0, 25)
	cBtn:RegisterForClicks("AnyDown")
	cBtn:SetScript("OnMouseUp", function()
		colorMenu:Hide()
		GUI:Hide()
		lock_all_frames = 1
		SendAddonMessage("oUF D3", "Frames locked", "WHISPER", UnitName("player"))
	end)
	
	--button one for locking/unlocking frames
	local cb1 = CreateFrame("CheckButton", "oUF_cb1", GUI, "UICheckButtonTemplate")
	cb1:SetWidth(35)
	cb1:SetHeight(35)
	cb1:SetPoint("TOPLEFT", g1, 50, -125)
	_G[cb1:GetName().."Text"]:SetText("Unlock/Lock")
	cb1:RegisterForClicks("AnyUp, AnyDown")
	local cb1Count = 0
	cb1:SetScript("OnMouseUp", function()
		if cb1Count == 0 then
			cb1:SetChecked(true)
			lock_all_frames = 0
			allow_frame_movement = 1
			orbPos_altered = 1
			if myclass == "PALADIN" or myclass == "WARLOCK" then
				power_moved = 1
			end
			SendAddonMessage("oUF D3", "Frames Movable", "WHISPER", UnitName("player"))
			am("Frames Movable")
			cb1Count = 1
		elseif cb1Count == 1 then
			cb1:SetChecked(false)
			lock_all_frames = 1
			SendAddonMessage("oUF D3", "Frames locked", "WHISPER", UnitName("player"))
			cb1Count = 0
			am("Frames Locked")
		end
	end)
	
	--button for hiding/showing power frame
	local cb2 = CreateFrame("CheckButton", "oUF_cb2", GUI, "UICheckButtonTemplate")
	cb2:SetWidth(35)
	cb2:SetHeight(35)
	cb2:SetPoint("TOPLEFT", g1, 200, -125)
	_G[cb2:GetName().."Text"]:SetText("Enable/Disable PowerWatch")
	cb2:RegisterForClicks("AnyUp, AnyDown")
	local cb2Count = 0
	cb2:SetScript("OnShow", function()
		if powers:IsVisible() then
			cb2:SetChecked(true)
			cb2Count = 1
		elseif not powers:IsVisible() then
			cb2:SetChecked(false)
			cb2Count = 0
		end
	end)
	cb2:SetScript("OnMouseUp", function()
		if myclass == "WARLOCK" or myclass == "PALADIN" then
			if cb2Count == 0 then
				cb2:SetChecked(true)
				update_powers = "show"
				load_power = 1
				SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
				am("The power frame will now be shown.")
				cb2Count = 1
			elseif cb2Count == 1 then
				cb2:SetChecked(false)
				update_powers = "hide"
				load_power = 0
				SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
				am("The power frame will now be hidden.")
				cb2Count = 0
			end
		else
			am("This option is only available to Paladins and Warlocks.")
		end		
	end)
	
	--checkbutton for showing/hiding artframes
	local cb3 = CreateFrame("CheckButton", "oUF_cb3", GUI, "UICheckButtonTemplate")
	cb3:SetWidth(35)
	cb3:SetHeight(35)
	cb3:SetPoint("TOPLEFT", g1, 430, -125)
	_G[cb3:GetName().."Text"]:SetText("Enable/Disable Art")
	cb3:RegisterForClicks("AnyUp, AnyDown")
	local cb3Count = 0
	cb3:SetScript("OnShow", function()
		if load_demon_angel == 1 or load_demon_angel == nil then
			cb3:SetChecked(true)
			cb3Count = 1
		elseif load_demon_angel == 0 then
			cb3:SetChecked(false)
			cb3Count = 0
		end
	end)
	cb3:SetScript("OnMouseUp", function()
			if cb3Count == 0 then
				cb3:SetChecked(true)
				update_liveAngelDemon = "show"
				load_demon_angel = 1
				SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
				am("Art surrounding orbs will now be shown.")
				cb3Count = 1
			elseif cb3Count == 1 then
				cb3:SetChecked(false)
				update_liveAngelDemon = "hide"
				load_demon_angel = 0
				SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
				am("Art surrounding orbs will now be hidden.")
				cb3Count = 0
			end
	end)
	
	--default positions button
	local dfBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	dfBtn:SetWidth(155)
	dfBtn:SetHeight(25)
	dfBtn:SetText("Default Positions")
	dfBtn:SetPoint("BOTTOM", g1, 200, 25)
	dfBtn:RegisterForClicks("AnyDown")
	dfBtn:SetScript("OnMouseUp", function()
		StaticPopupDialogs["Reset Positions"] = {
		text = "Are you sure you want to reset all frames to their default positions?",
		button1 = "Yes, do it",
		button2 = "No",
		OnAccept = function()
			orbPos_altered = nil
			power_moved = nil
			lock_all_frames = 1
			allow_frame_movement = 0
			cb1:SetChecked(false)
			SendAddonMessage("oUF D3", "Frames Reset", "WHISPER", UnitName("player"))
			am("Frames in default position.")	
	end,
		timeout = 0,
		whileDead = true,
		hideOnEscape = true,
		}
		StaticPopup_Show("Reset Positions")
	end)
	
	local dfsBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	dfsBtn:SetWidth(100)
	dfsBtn:SetHeight(25)
	dfsBtn:SetText("Default Sizes")
	dfsBtn:SetPoint("BOTTOM", g1, 200, 53)
	dfsBtn:RegisterForClicks("AnyDown")
	dfsBtn:SetScript("OnMouseUp", function()
		StaticPopupDialogs["Reset Positions"] = {
		text = "Are you sure you want to reset all frames to their default sizes?",
		button1 = "Yes, do it",
		button2 = "No",
		OnAccept = function()
			playerscale = scale_default
			SendAddonMessage("oUF D3", "Scale Changed", "WHISPER", UnitName("player"))
			am("Orb scale reset to default.")
		end,
		timeout = 0,
		whileDead = true,
		hideOnEscape = true,
		}
		StaticPopup_Show("Reset Positions")
	end)

	--default colors btn
	local dfcBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	dfcBtn:SetWidth(125)
	dfcBtn:SetHeight(25)
	dfcBtn:SetText("Default Colors")
	dfcBtn:SetPoint("BOTTOM", g1, -210, 25)
	dfcBtn:RegisterForClicks("AnyDown")
	dfcBtn:SetScript("OnMouseUp", function()
		StaticPopupDialogs["Reset Colors"] = {
		text = "Are you sure you want to reset all colors back to their defaults?",
		button1 = "Yes, do it",
		button2 = "No",
		OnAccept = function()
			set_combat_color = nil
			set_mana_color = nil
			set_health_color = nil
			set_kitty_mana = nil
			set_bear_mana = nil
			set_d3_colors()
			SendAddonMessage("oUF D3 Orbs", "Colors Changed", "WHISPER", UnitName("player"))
			stringcheck = "changed"
			am("All colors have been set back to their original defaults.")		
	end,
		timeout = 0,
		whileDead = true,
		hideOnEscape = true,
		}
		StaticPopup_Show("Reset Colors")
	end)
		
	--button for opening health color selection
	local 	clicked1 = false
	local	clicked2 = false
	local	clicked3 = false    -- button counters
	local	clicked4 = false
	local	clicked5 = false
	local hBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	hBtn:SetWidth(75)
	hBtn:SetHeight(25)
	hBtn:SetText("Health Orb")
	hBtn:SetPoint("CENTER", g1, -225, -30)
	hBtn:RegisterForClicks("AnyDown")
	hBtn:SetScript("OnMouseUp", function()
		if clicked1 == false then
			clicked2 = false
			clicked3 = false
			clicked4 = false
			clicked5 = false
			colorMenu:SetPoint("CENTER", g1, -225, -75)
			colorMenu:Hide()
			colorMenu:Show()
			clicked1 = true
		elseif clicked1 == true then
			colorMenu:Hide()
			clicked1 = false
		end
	end)	
	
	--button for opening color selection
	local mBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	mBtn:SetWidth(75)
	mBtn:SetHeight(25)
	local mBtnx = -115
	mBtn:SetText("Mana Orb")
	mBtn:SetPoint("CENTER", g1, mBtnx,-30)
	mBtn:RegisterForClicks("AnyDown")
	mBtn:SetScript("OnMouseUp", function()
		if clicked2 == false then
			clicked1 = false
			clicked3 = false
			clicked4 = false
			clicked5 = false
			colorMenu:SetPoint("CENTER", g1, mBtnx, -75)
			colorMenu:Hide()
			colorMenu:Show()
			clicked2 = true
		elseif clicked2 == true then
			colorMenu:Hide()
			clicked2 = false
		end
	end)	
	
	--button for opening druid mana color selection
	local kmBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	kmBtn:SetWidth(78)
	kmBtn:SetHeight(25)
	kmBtn:SetText("Kitty Mana")
	kmBtn:SetPoint("CENTER", g1, -5,-30)
	if myclass == "DRUID" then
		kmBtn:RegisterForClicks("AnyDown")
	else
		kmBtn:Hide()
		mBtnx = -10
		mBtn:ClearAllPoints()
		mBtn:SetPoint("CENTER", g1, mBtnx, -30)
	end
	kmBtn:SetScript("OnMouseUp", function()
		if clicked3 == false then
			clicked1 = false
			clicked2 = false
			clicked4 = false
			clicked5 = false
			colorMenu:SetPoint("CENTER", g1, -5, -75)
			colorMenu:Hide()
			colorMenu:Show()
			clicked3 = true
		elseif clicked3 == true then
			colorMenu:Hide()
			clicked3 = false
		end
	end)	
		
	--button for opening bear mana color selection
	local bmBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	bmBtn:SetWidth(78)
	bmBtn:SetHeight(25)
	bmBtn:SetText("Bear Mana")
	bmBtn:SetPoint("CENTER", g1, 105, -30)
	if myclass == "DRUID" then
		bmBtn:RegisterForClicks("AnyDown")
	else
		bmBtn:Hide()
	end
	bmBtn:SetScript("OnMouseUp", function()
		if clicked4 == false then
			clicked1 = false
			clicked2 = false
			clicked3 = false
			clicked5 = false
			colorMenu:SetPoint("CENTER", g1, 105, -75)
			colorMenu:Hide()
			colorMenu:Show()
			clicked4 = true			
		elseif clicked4 == true then
			colorMenu:Hide()
			clicked4 = false
		end
	end)	
	
	--button for opening combat color selection
	local cmBtn = CreateFrame("Button", "ARTWORK", GUI, "UIPanelButtonTemplate")
	cmBtn:SetWidth(99)
	cmBtn:SetHeight(25)
	cmBtn:SetText("Combat Color")
	cmBtn:SetPoint("CENTER", g1, 225, -30)
	cmBtn:RegisterForClicks("AnyDown")
	cmBtn:SetScript("OnMouseUp", function()
		if clicked5 == false then
			clicked2 = false
			clicked3 = false
			clicked4 = false
			clicked1 = false
			colorMenu:SetPoint("CENTER", g1, 225, -75)
			colorMenu:Hide()
			colorMenu:Show()
			clicked5 = true
		elseif clicked5 == true then
			colorMenu:Hide()
			clicked5 = false
		end
	end)	

		--drop down menu to be implemented within buttons
	CreateFrame("Frame", "colorMenu", GUI, "UIDropDownMenuTemplate")
	colorMenu:ClearAllPoints()
	local fillColors = {
		"Default",
		"Red",
		"Green",
		"Blue",
		"Yellow",
		"Runic",
		"Purple",
		"White",
		"Pink",
		"Orange",
		"Tan",
		"Focus",
	}
	
	colorMenu:SetScript("OnShow", function()
		UIDropDownMenu_SetText(colorMenu, "Click to change")
	end)
	local function OnClick(self)
		UIDropDownMenu_SetSelectedID(colorMenu, self:GetID())
		--function with passed values to colorSelector
		local name 
		if clicked1 == true then
			name = "hOrb"
		elseif clicked2 == true then
			name = "mOrb"
		elseif clicked3 == true then
			name = "kMana"
		elseif clicked4 == true then
			name = "bMana"
		elseif clicked5 == true then
			name = "cOrb"
		end
		colorSelector(name, self:GetID()-1)
	end
	local function initMen(self, level)
		local stuff = UIDropDownMenu_CreateInfo()
		for k,v in pairs(fillColors) do
			stuff = UIDropDownMenu_CreateInfo()
			stuff.text = v
			stuff.value = v
			stuff.func = OnClick
			UIDropDownMenu_AddButton(stuff, level)
		end
	end
	UIDropDownMenu_Initialize(colorMenu, initMen)
	UIDropDownMenu_SetWidth(colorMenu, 107);
	UIDropDownMenu_SetButtonWidth(colorMenu, 124)
	UIDropDownMenu_SetSelectedID(colorMenu, 1)
	UIDropDownMenu_JustifyText(colorMenu, "LEFT")
	
	--frame to tell users about new menu
	local notify = CreateFrame("Frame", nil)
	notify:RegisterEvent("PLAYER_LOGIN")
	notify:SetScript("OnEvent", function()
			am("The Diablo 3 Orbs have a new menu!  Type /d3 to view.")
			am("Playerscale value is: " .. playerscale)
	end)
	
	--slide bar for scaling
	local slScale = CreateFrame("Slider", "slScale_Slider", GUI, "OptionsSliderTemplate")
	slScale:SetOrientation('HORIZONTAL')
	slScale:SetWidth(100)
	slScale:SetHeight(20)
	slScale:SetPoint("CENTER", g1, 4, -180)
	slScale.tooltipText = 'Sets the orb scale'
	slScale:SetThumbTexture("Interface\\Buttons\\UI-SliderBar-Button-Horizontal")
	slScale:SetValueStep(.01)
	slScale:SetBackdrop({
		bgFile = "Interface\\Buttons\\UI-SliderBar-Background",
		edgeFile = "Interface\\Buttons\\UI-SliderBar-Border",
		tile = true, tileSize = 8, edgeSize = 8,
		insets = { left = 3, right = 3, top = 6, bottom = 6 }})
	slScale:SetValue(0.5)
	slScale:SetMinMaxValues(0.5,1.5)
	slScale:SetScript("OnShow", function()
		slScale:SetValue(playerscale)
	end)
	slScale:RegisterEvent("CHAT_MSG_ADDON")
	slScale:SetScript("OnEvent", function(_,event,arg1,arg2)
		if arg2 == "Scale Changed" then
			slScale:SetValue(playerscale)
		end
	end)
	slScale:SetScript("OnValueChanged", function()
		getglobal(slScale:GetName() .. 'Text'):SetText('Global Scale: ' .. string.format("%0d",slScale:GetValue() * 100) .. '%')
		playerscale = slScale:GetValue()
		SendAddonMessage("oUF D3 Orbs", "Scale Changed", "WHISPER", UnitName("player"))
	end)
	getglobal(slScale:GetName() .. 'Low'):SetText('1')
	getglobal(slScale:GetName() .. 'High'):SetText('100')
	getglobal(slScale:GetName() .. 'Text'):SetText('Current Value: ' .. string.format("%0d",slScale:GetValue() * 100) .. '%')
	--[[*****************************************************************************************************************
												Minimap Button
							(Thank you to the author of MyMinimapButton for help here)
									   (To be finished at a later date)
	*******************************************************************************************************************]]
	--[[
	local mButton = CreateFrame("Button", mName, Minimap)
	mButton:SetFrameStrata("LOW")
	mButton:SetHeight(31)
	mButton:SetWidth(31)
	mButton:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
	mButton:SetPoint("TOPLEFT",Minimap,"TOPLEFT")
	local pic = mButton:CreateTexture(nil, "BACKGROUND")
	pic:SetTexture("Interface\\AddOns\\oUF_D3Orbs_Light\\rTextures\\mButtonIcon")
	pic:SetHeight(20)
	pic:SetWidth(20)
	pic:SetPoint("TOPLEFT",mButton,"TOPLEFT",7,-5)
	mOverlay = mButton:CreateTexture(nil, "OVERLAY")
	mOverlay:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
	mOverlay:SetWidth(53)
	mOverlay:SetHeight(53)
	mOverlay:SetPoint("TOPLEFT",mButton,"TOPLEFT")
	mButton:Show()
	
	local function Move(self, xloc, yloc)
	end]]
	
	local function SlashCmd(cmd,self)
	--set health orb color
	if (cmd:match"menu") then
		if g1:IsVisible() then
			GUI:Hide()
		else
			GUI:Show()
		end
	elseif (cmd:match"sethealth") then
		local a,b = strfind(cmd, " ");
		if b then
			local c = strsub(cmd, b+1)
			if c == "red" or c == "green" or c == "blue" or c == "yellow" or c == "runic" or c == "purple" or c == "white" or c == "pink" or c == "orange" or c == "tan" or c == "focus"
				or c == "default" then	
					if c == "red" then
						set_health_color = 1
					elseif c == "green" then
						set_health_color = 2
					elseif c == "blue" then
						set_health_color = 3 
					elseif c == "yellow" then
						set_health_color = 4
					elseif c == "runic" then
						set_health_color = 5
					elseif c == "purple" then
						set_health_color = 7
					elseif c == "white" then
						set_health_color = 8
					elseif c == "pink" then
						set_health_color = 9
					elseif c == "orange" then
						set_health_color = 10
					elseif c == "tan" then
						set_health_color = 11
					elseif c == "focus" then
						set_health_color = 12
					elseif c == "default" then
						set_health_color = 0
					end				
					c = c:gsub("%a", string.upper, 1)
					am("The health color has now been set to: "..c)
					set_d3_colors()
					SendAddonMessage("oUF D3 Orbs", "Colors Changed", "WHISPER", UnitName("player"))
					stringcheck = "changed"
			else
				am("Wrong value entered.  Possible values are red, green, blue, yellow, runic, purple, white, pink, orange, tan or default.")
			end
		else
			am("No action found.")
		end
	--set mana orb color
	elseif (cmd:match"setmana") then
		local a,b = strfind(cmd, " ");
		if b then
			local c = strsub(cmd, b+1)
			if c == "red" or c == "green" or c == "blue" or c == "yellow" or c == "runic" or c == "purple" or c == "white" or c == "pink" or c == "orange" or c == "tan" or c == "focus"
				or c == "default" then	
				if c == "red" then
					set_mana_color = 1
				elseif c == "green" then
					set_mana_color = 2
				elseif c == "blue" then
					set_mana_color = 3
				elseif c == "yellow" then
					set_mana_color = 4
				elseif c == "runic" then
					set_mana_color = 5
				elseif c == "purple" then
					set_mana_color = 7
				elseif c == "white" then
					set_mana_color = 8
				elseif c == "pink" then
					set_mana_color = 9
				elseif c == "orange" then
					set_mana_color = 10
				elseif c == "tan" then
					set_mana_color = 11
				elseif c == "focus" then
					set_mana_color = 12
				elseif c == "default" then
					set_mana_color = 3
				end
				c = c:gsub("%a", string.upper, 1)
				am("The mana color has now been set to: "..c)
				set_d3_colors()
				SendAddonMessage("oUF D3 Orbs", "Colors Changed", "WHISPER", UnitName("player"))
				stringcheck = "changed"
			else
				am("Wrong value entered.  Possible values are red, green, blue, yellow, runic, purple, white, pink, orange, or default.")
			end
		else
			am("No action found.")
		end
	--set combat color
	elseif (cmd:match"setcombat") then
		local a,b = strfind(cmd, " ");
		if b then
			local c = strsub(cmd, b+1)
			if c == "red" or c == "green" or c == "blue" or c == "yellow" or c == "runic" or c == "purple" or c == "white" or c == "pink" or c == "orange" or c == "tan" or c == "focus"
				or c == "default" then	

				if c == "red" then
					set_combat_color = 1
				elseif c == "green" then
					set_combat_color = 2
				elseif c == "blue" then
					set_combat_color = 3
				elseif c == "yellow" then
					set_combat_color = 4
				elseif c == "runic" then
					set_combat_color = 5
				elseif c == "purple" then
					set_combat_color = 6
				elseif c == "white" then
					set_combat_color = 7
				elseif c == "pink" then
					set_combat_color = 8
				elseif c == "orange" then
					set_combat_color = 9
				elseif c == "tan" then
					set_combat_color = 10
				elseif c == "focus" then
					set_combat_color = 11
				elseif c == "default" then
					set_combat_color = 1
				end	
				c = c:gsub("%a", string.upper, 1)
				am("The combat color has been set to: "..c)
			else
				am("Wrong value entered.  Possible values are red, green, blue, yellow, runic, purple, white, pink, orange, tan or default.")
			end
		else
			am("No action found.")
		end
		--set colors back to default
	elseif (cmd:match"setcolordefaults") then
		set_combat_color = nil
		set_mana_color = nil
		set_health_color = nil
		set_kitty_mana = nil
		set_bear_mana = nil
		set_d3_colors()
		SendAddonMessage("oUF D3 Orbs", "Colors Changed", "WHISPER", UnitName("player"))
		stringcheck = "changed"
		am("All colors have been set back to their original defaults.")
	--set druid kitty form mana color	
	elseif (cmd:match"setcatmana") then
		local a,b = strfind(cmd, " ");
		if b then
			local c = strsub(cmd, b+1)
			if myclass == "DRUID" then
			if c == "red" or c == "green" or c == "blue" or c == "yellow" or c == "runic" or c == "purple" or c == "white" or c == "pink" or c == "orange" or c == "tan" or c == "focus"
				or c == "default" then	
					if c == "red" then
						set_kitty_mana = 1
					elseif c == "green" then
						set_kitty_mana = 2
					elseif c == "blue" then
						set_kitty_mana = 3
					elseif c == "yellow" then
						set_kitty_mana = 4
					elseif c == "runic" then
						set_kitty_mana = 5
					elseif c == "purple" then
						set_kitty_mana = 7
					elseif c == "white" then
						set_kitty_mana = 8
					elseif c == "pink" then
						set_kitty_mana = 9
					elseif c == "orange" then
						set_kitty_mana = 10
					elseif c == "tan" then
						set_kitty_mana = 11
					elseif c == "focus" then
						set_kitty_mana = 12
					elseif c == "default" then
						set_kitty_mana = 4
					end
					c = c:gsub("%a", string.upper, 1)
					am("Cat form mana color has been set to: "..c)
					set_d3_colors()
					SendAddonMessage("oUF D3 Orbs", "Colors Changed", "WHISPER", UnitName("player"))
					stringcheck = "changed"
				else
					am("Wrong value entered.  Possible values are red, green, blue, yellow, runic, purple, white, pink, orange, tan or default.")
				end
			else
				am("You're not a druid!")
			end
		else
			am("No action found.")
		end
	--set druid bear form mana color
	elseif (cmd:match"setbearmana") then
		local a,b = strfind(cmd, " ");
		if b then
			local c = strsub(cmd, b+1)
			if myclass == "DRUID" then
			if c == "red" or c == "green" or c == "blue" or c == "yellow" or c == "runic" or c == "purple" or c == "white" or c == "pink" or c == "orange" or c == "tan" or c == "focus"
				or c == "default" then	

					if c == "red" then
						set_bear_mana = 1
					elseif c == "green" then
						set_bear_mana = 2
					elseif c == "blue" then
						set_bear_mana = 3
					elseif c == "yellow" then
						set_bear_mana = 4
					elseif c == "runic" then
						set_bear_mana = 5
					elseif c == "purple" then
						set_bear_mana = 7
					elseif c == "white" then
						set_bear_mana = 8
					elseif c == "pink" then
						set_bear_mana = 9
					elseif c == "orange" then
						set_bear_mana = 10
					elseif c == "tan" then
						set_bear_mana = 11
					elseif c == "focus" then
						set_bear_mana = 12
					elseif c == "default" then
						set_bear_mana = 1
					end
					c = c:gsub("%a", string.upper, 1)
					am("Bear form mana color has been set to:"..c)
					set_d3_colors()
					SendAddonMessage("oUF D3 Orbs", "Colors Changed", "WHISPER", UnitName("player"))
					stringcheck = "changed"					
				else
					am("Wrong value entered.  Possible values are red, green, blue, yellow, runic, purple, white, pink, orange, tan or default.")
				end
			else
				am("You're not a druid!")
			end
		else
			am("No action found.")
		end
	--make orbs movable via menu command
	elseif (cmd:match"movestuff") then
		lock_all_frames = 0
		allow_frame_movement = 1
		orbPos_altered = 1
		power_moved = 1
		SendAddonMessage("oUF D3", "Frames Movable", "WHISPER", UnitName("player"))
		am("Frames Movable")
	elseif (cmd:match"donemoving") then
		lock_all_frames = 1
		SendAddonMessage("oUF D3", "Frames locked", "WHISPER", UnitName("player"))
		am("Frames Locked")
	elseif (cmd:match"defaultpositions") then
		orbPos_altered = nil
		power_moved = nil
		lock_all_frames = 1
		allow_frame_movement = 0
		SendAddonMessage("oUF D3", "Frames Reset", "WHISPER", UnitName("player"))
		am("Frames in default position.")
	elseif (cmd:match"powerframe") then
		local a,b = strfind(cmd, " ");
			if b then
				local c =strsub(cmd, b+1)
				if c == "show" then
					update_powers = "show"
					load_power = 1
					SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
					am("The power frame will now be shown.")
				elseif c == "hide" then
					update_powers = "hide"
					load_power = 0
					SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
					am("The power frame will now be hidden.")
				elseif c == "getvalue" then
					am("Power frame set to:"..load_power..":  * if 0 then frame will be hidden * ")
				else
					am("Wrong value entered.  Possible values are show, and hide.")
				end
			else
				am("No action found.")
			end	
	elseif (cmd:match"artframes") then
		local a,b = strfind(cmd, " ");
			if b then
				local c = strsub(cmd, b+1)
				if c == "show" then
					update_liveAngelDemon = "show"
					load_demon_angel = 1
					SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
					am("Art surrounding orbs will now be shown.")
				elseif c == "hide" then
					update_liveAngelDemon = "hide"
					load_demon_angel = 0
					SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
					am("Art surrounding orbs will now be hidden.")
				elseif c == "getvalue" then
					am("Art set to:"..load_demon_angel..":  * if 0 then art will not show * ")
				else
					am("Wrong value entered.  Possible values are show, and hide.")
				end
			else
				am("No action found.")
			end	
	elseif (cmd:match"playerframe") then
		local a,b = strfind(cmd, " ");
			if b then
				local c = strsub(cmd, b+1)
				if c == "show" then
					showPFrame = true
					load_playerFrame = 1
					SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
					am("Blizzard player frame will now be shown.")
				elseif c == "hide" then
					showPFrame = false
					load_playerFrame = 0 
					SendAddonMessage("oUF D3", "Frames Hidden", "WHISPER", UnitName("player"))
					am("Blizzard player frame will now be hidden.")
				end
			end
		--check combat, health, and manacolors
	elseif (cmd:match"getvalues") then
		local check
		--check health color
		if set_health_color == 1 then
			check = "Red"
		elseif set_health_color == 2 then
			check = "Green"
		elseif set_health_color == 3 then
			check = "Blue"
		elseif set_health_color == 4 then
			check = "Yellow"
		elseif set_health_color == 5 then
			check = "Runic"
		elseif set_health_color == 7 then
			check = "Purple"
		elseif set_health_color == 8 then
			check = "White"
		elseif set_health_color == 9 then
			check = "Pink"
		elseif set_health_color == 10 then
			check = "Orange"
		elseif set_health_color == 11 then
			check = "Tan"
		elseif set_health_color == 12 then
			check = "Focus"
		else
			check = "Default"
		end
		print("The health orb color is: "..check)
		--check mana color
		if set_mana_color == 1 then
			check = "Red"
		elseif set_mana_color == 2 then
			check = "Green"
		elseif set_mana_color == 3 then
			check = "Blue"
		elseif set_mana_color == 4 then
			check = "Yellow"
		elseif set_mana_color == 5 then
			check = "Runic"
		elseif set_mana_color == 7 then
			check = "Purple"
		elseif set_mana_color == 8 then
			check = "White"
		elseif set_mana_color == 9 then
			check = "Pink"
		elseif set_mana_color == 10 then
			check = "Orange"
		elseif set_mana_color == 11 then
			check = "Tan"
		elseif set_mana_color == 12 then
			check = "Focus"
		else
			check = "Default"
		end
		print("The mana orb color is: "..check)
		--check combat color
		if set_combat_color == 1 then
			check = "Red"
		elseif set_combat_color == 2 then
			check = "Green"
		elseif set_combat_color == 3 then
			check = "Blue"
		elseif set_combat_color == 4 then
			check = "Yellow"
		elseif set_combat_color == 5 then
			check = "Runic"
		elseif set_combat_color == 7 then
			check = "Purple"
		elseif set_combat_color == 8 then
			check = "White"
		elseif set_combat_color == 9 then
			check = "Pink"
		elseif set_combat_color == 10 then
			check = "Orange"
		elseif set_combat_color == 11 then
			check = "Tan"
		elseif set_combat_color == 12 then
			check = "Focus"
		else
			check = "Default"
		end
		print("The combat color is: "..check)
		--check cat mana color
		if set_kitty_mana == 1 then
			check = "Red"
		elseif set_kitty_mana == 2 then
			check = "Green"
		elseif set_kitty_mana == 3 then
			check = "Blue"
		elseif set_kitty_mana == 4 then
			check = "Yellow"
		elseif set_kitty_mana == 5 then
			check = "Runic"
		elseif set_kitty_mana == 7 then
			check = "Purple"
		elseif set_kitty_mana == 8 then
			check = "White"
		elseif set_kitty_mana == 9 then
			check = "Pink"
		elseif set_kitty_mana == 10 then
			check = "Orange"
		elseif set_kitty_mana == 11 then
			check = "Tan"
		elseif set_kitty_mana == 12 then
			check = "Focus"
		else
			check = "Default"
		end
		print("The cat form mana color is: "..check)
		--check bear mana color
		if set_bear_mana == 1 then
			check = "Red"
		elseif set_bear_mana == 2 then
			check = "Green"
		elseif set_bear_mana == 3 then
			check = "Blue"
		elseif set_bear_mana == 4 then
			check = "Yellow"
		elseif set_bear_mana == 5 then
			check = "Runic"
		elseif set_bear_mana == 7 then
			check = "Purple"
		elseif set_bear_mana == 8 then
			check = "White"
		elseif set_bear_mana == 9 then
			check = "Pink"
		elseif set_bear_mana == 10 then
			check = "Orange"
		elseif set_bear_mana == 11 then
			check = "Tan"
		elseif set_bear_mana == 12 then
			check = "Focus"
		else
			check = "Default"
		end
		print("The bear form mana color is: "..check)
	elseif (cmd:match"powertest") then
		local a = UnitPower("player", 9)
		print(a)
	elseif (cmd:match"scale") then
		print(playerscale)
	else
		if g1:IsVisible() then
			GUI:Hide()
		else
			GUI:Show()
		end
		--[[am("Possible entries are /d3 sethealth, setmana, setcombat, setcolordefaults, setcatmana, setbearmana, or getvalues.  Type a color after sethealth, setmana, or setcombat.")
		am("Possible colors are red, green, blue, yellow, runic, purple, white, pink, orange, tan, focus and default.")
		am("Example: /d3 sethealth runic - this will set your health color to runic, /d3 sethealth default will set the healthcolor to class default.  /d3 setdcolordefaults will restore all colors.")
		am(" ***/d3 movestuff *** this will allow you to move the orbs, and the art by holding shift, alt, and dragging.   ***/d3 donemoving*** this will lock the frames in place.")
		am(" ***/d3 defaultpositions *** this will restore the default positions back to the orbs, and the artwork.  ***/d3 artframes show/hide *** show will use the orb art, hide will hide it.")
		]]
	end
end --end of slash command function

--load everything
SlashCmdList["D3Stuff"] = SlashCmd;
SLASH_D3Stuff1 = "/d3"; --end of slash command list